Skip to content Skip to sidebar Skip to footer

How To Add Touch Event To Show Latitude And Longitude In A Toast In OSM

How do I add this function below in my code? The url is this: how to add more marker in osm map in android please help me? I want to add feature to print toast message of every

Solution 1:

Use this piece of code and create an object of this class and add it to the mapsOverlay

class MapOverlay extends com.google.android.maps.Overlay
{
    @Override
    public boolean draw(Canvas canvas, MapView mapView, 
    boolean shadow, long when) 
    {
       //...
    }

    @Override
    public boolean onTouchEvent(MotionEvent event, MapView mapView) 
    {   
        //---when user lifts his finger---
        if (event.getAction() == MotionEvent.ACTION_UP) {                
            GeoPoint p = mapView.getProjection().fromPixels(
                (int) event.getX(),
                (int) event.getY());
                Toast.makeText(getBaseContext(), 
                    p.getLatitudeE6() / 1E6 + "," + 
                    p.getLongitudeE6() /1E6 , 
                    Toast.LENGTH_SHORT).show();
        }                            
        return false;
    }        
}

add this line

mapView.getOverlays().add(new MapOverlay());

Post a Comment for "How To Add Touch Event To Show Latitude And Longitude In A Toast In OSM"