嗨我需要一些幫助,我已經看過並嘗試許多不同的事情。我試圖讓我在android上的當前位置,但由於位置返回null我的應用程序崩潰。我真的需要這方面的幫助。谷歌地圖v2 API的Android位置返回null
我不知道我是否在這裏清楚,但每次我調用getLastKnownlocation它回來爲空,所以當我嘗試獲得雙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);
是它停止。
你得到的 字符串提供商提供什麼= locationManager.getBestProvider(標準,真正的);? – CAA 2015-03-02 14:41:24
從來沒有一個位置返回給你,所以你必須始終檢查一個空位置 – tyczj 2015-03-02 14:56:40
@CAA我得到的提供商是這條線上的GPS – 2015-03-02 15:30:52