Search code examples
androidmonogeolocationxamarin.androidmapactivity

Mono for Android: Reverse GeoCoding Current Location


Using the MyLocationOverlay I get the current GeoPoint of the user.

        myLocationOverlay.RunOnFirstFix (() => {
            mapView.Controller.AnimateTo (myLocationOverlay.MyLocation);
            RunOnUiThread (() => {
                DisplayIncidentsNearMe (myLocationOverlay.MyLocation);}
            );
        }
        );

However, To ReverseGeoCode that location, I need the Lat/Lng. The GeoPoint from the MyLocationOverlay is in LatitudeE6 format so doesn't work.

How do I get the "normal" lat/lng from the location object returned from the MyLocationOverlay?

        Geocoder geo = new Geocoder (this, Java.Util.Locale.Default);
        var ad = geo.GetFromLocation (myLocation.LatitudeE6, myLocation.LongitudeE6, 1);

Solution

  • From the GeoPoint documentation, LatitudeE6 is:

    the latitude of this GeoPoint in microdegrees (degrees * 1E6).

    You can convert this number back to degrees by dividing by 1e6:

    double degrees = myLocation.LatitudeE6 / 1e6;