下面的代码给出NullPointerException
是否有其他方法可以在Android应用中获取当前位置
LocationListener locationListener = new LocationListener()
{
public void onLocationChanged(Location location) {}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE)
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double latitude = location.getLatitude(); //NullPointerException
double longitude = location.getLongitude();
答案 0 :(得分:0)
确定您可以使用google play服务位置API: http://developer.android.com/google/play-services/location.html
但也许你应该首先看看你的问题...看看这个问题的空问题: android getlastknownlocation returns null