Android - Location by LocationManager different from GoogleMaps

风格不统一 提交于 2019-12-08 00:25:46

问题


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



来源:https://stackoverflow.com/questions/16822861/android-location-by-locationmanager-different-from-googlemaps

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!