How to get the Latitude and Longitude on Map in Android?

Praveen picture Praveen · Dec 15, 2010 · Viewed 19.2k times · Source

How can I get the Latitude and Longitude values of a particular location that I have long clicked on the map in Android?

Answer

Vetsin picture Vetsin · Dec 15, 2010

For the long click, I suggest you check out http://www.kind-kristiansen.no/2010/handling-longpresslongclick-in-mapactivity/. This will go into detail on how to listen for long click events within the Maps API since there is little or no built-in functionality that I know of.

As for the lat/lng code, after you get the long click you can translate the pixels to coordinates.

public void recieveLongClick(MotionEvent ev)
{
    Projection p = mapView.getProjection();
    GeoPoint geoPoint = p.fromPixels((int) ev.getX(), (int) ev.getY());
    // You can now pull lat/lng from geoPoint
}