Accurate latitude and longitude of current location in android

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

In my application, I am showing map with marker at the current location s latitude and longitude.And I use Map.setMyLocationEnabled(true) for user to interact with their location.

What my problem is setMyLocationEnabled method and my location - lat,long code is marks different positions as follows:

<img src="https://i.stack.imgur.com/SdZ7e.png" alt="Map">

I have used the following code to get Latitude and Longitude of current location:

    LocationManager locationManager = (LocationManager)  getSystemService(Context.LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    provider = locationManager.getBestProvider(criteria, true);
    Location location = locationManager.getLastKnownLocation(provider);
    if(location!=null){
        latitude = location.getLatitude();
        longitude = location.getLongitude();
         --------- 
         }
  How to get accurate latitude and longitude of my current location as google s setLocationEnabled provided?   
Green flag marker is my marker and blue dot is android provided.

Answers

Instead of using LocationManager, add yourself to GoogleMap s location client via setOnMyLocationChangeListener. It returns the same location blue dot is pointing to.

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/18018011/accurate-latitude-and-longitude-of-current-location-in-android

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils