我正在使用 GPS。这是我的代码。
public void onCreate()
{
super.onCreate();
mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location mLocation;
if(mLocationManager.isProviderEnabled((LocationManager.GPS_PROVIDER)))
{
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER , 2000, 10, myLocationListener);
mLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
Temp = updateWithNewLocation(mLocation);
Value.city = Temp;
Temp = "";
LogShow("DataClass.City = " + Value.city);
LogShow("GPS_PROVIDER enable");
}
}
我不知道为什么 getLastKnownLocation 返回 NULL。所以 updateWithNewLocation 将为空。我使用权限 ACCESS FINE LOCATION。
我该如何解决?