【发布时间】:2015-03-02 14:38:40
【问题描述】:
您好,我需要一些帮助,我已经查看并尝试了许多不同的东西。我正在尝试在 android 上获取我当前的位置,但由于该位置返回 null,我的应用程序崩溃了。我真的需要帮助。
我不知道我在这里是否清楚,但每次我调用 getLastKnownlocation 它都会返回 null,所以当我尝试让双 lat= location.getLatitude() 与经度相同时,它不会返回任何东西都会在我的应用崩溃的地方。
帮助... 这里有一段代码
mMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager)getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
mMap.setMapType(GoogleMap.MAP_TYPE_HYBRID);
double lat = location.getLatitude();
double lng = location.getLongitude();
LatLng latLng = new LatLng(lat, lng);
在纬度是它停止的地方。
【问题讨论】:
-
你在 String provider = locationManager.getBestProvider(criteria, true); 得到什么提供者?
-
永远不必将位置返回给您,因此您必须始终检查空位置
-
@CAA 我得到的提供者是这条线上的GPS
-
尝试在你的
Mainactivity中添加findLocation方法,请参考here
标签: android google-maps google-maps-android-api-2 google-maps-api-2