Android - Location by LocationManager different fr

2019-05-23 14:23发布

问题:

I have created a location listener by 'LocationManager' with this code:

mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 100, 100, mListenerNetwork);

and the listener:

LocationListener mListenerNetwork = new LocationListener() {
    public void onLocationChanged(Location location) {
        // New Location by LocationManager
    }

    public void onProviderDisabled(String provider) { }

    public void onProviderEnabled(String provider) { }

    public void onStatusChanged(String provider, int status, Bundle extras)  { }
}

And I have a listener by google maps API:

getMap().setOnMyLocationChangeListener(this);

and the listener:

public void onMyLocationChange(Location location) {
    // New Location by GoogleMaps       
}

When I debugged the application, I have noticed that the locations in the listeners are different! More than that, the accuracy of the location are very different. The accuracy in the Google Maps is half of the accuracy in LocationManager (less is better).
Why the locations are so different?

回答1:

Most likely GoogleMaps is using new LocationClient API, which was announced on Google I/O 2013. You may want to switch to this API too.

It is said to be more accurate and use less battery.

More info on how to get location updates: http://developer.android.com/training/location/receive-location-updates.html



回答2:

Your call to requestLocationUpdates is only requesting location updates from the Network Location Provider (LocationManager.NETWORK_PROVIDER). The Network Location Provider uses cell tower and WiFi signals to determine location. There is also a GPS Location Provider (LocationManager.GPS_PROVIDER) which uses GPS satellites and is far more accurate when satellites are available. Google Maps is most likely using a combination of the two location providers to determine the most accurate position.

Take a look at this guide for some more insight into the best way to utilize Android's location services for your needs: http://developer.android.com/guide/topics/location/strategies.html