Zhet Asked: 2020-12-14 16:24:37 +0800 CST 2020-12-14 16:24:37 +0800 CST 2020-12-14 16:24:37 +0800 CST 获取经纬度(位置)谷歌地图 772 我希望能够在一个android项目中确定我当前的位置,为了获得我的位置的纬度和经度以在特定的方法中使用它们,我已经查看了已解决的问题,但我不明白代码他们已经给出了答案,如果你能帮我一把,我将不胜感激 android 2 Answers Voted Best Answer sioesi 2020-12-14T16:27:43+08:002020-12-14T16:27:43+08:00 与您在其他问题中给出的答案之一一样,它被使用LocationManager LocationManager lm = (LocationManager)getSystemService(Context.LOCATION_SERVICE); Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); double longitude = location.getLongitude(); double latitude = location.getLatitude(); 这将为您带来当前位置,如果没有当前位置,它显然会返回 null 但是有一种方法可以异步完成这项工作 private final LocationListener locationListener = new LocationListener() { public void onLocationChanged(Location location) { longitude = location.getLongitude(); latitude = location.getLatitude(); } } lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener); 启动应用时如何获取经纬度: @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); Criteria criteria = new Criteria(); String bestProvider = locationManager.getBestProvider(criteria, true); Location location = locationManager.getLastKnownLocation(bestProvider); if (location != null) { onLocationChanged(location); } locationManager.requestLocationUpdates(bestProvider, 20000, 0, this); Hernan Humaña 2020-12-14T18:27:54+08:002020-12-14T18:27:54+08:00 您看到 apache cordova 文档了吗?那里似乎怎么做,我做到了,但是在离子中。我把链接留给你,问候。 https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/
与您在其他问题中给出的答案之一一样,它被使用
LocationManager
这将为您带来当前位置,如果没有当前位置,它显然会返回 null 但是有一种方法可以异步完成这项工作
启动应用时如何获取经纬度:
您看到 apache cordova 文档了吗?那里似乎怎么做,我做到了,但是在离子中。我把链接留给你,问候。
https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/