Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get lat and long on touch event from google map?

Is it possible to get latitude and longitude from Google map on touch event?

For example: if i touch the New York on map, it should give me the latitude and longitude of New York.

like image 436
Hitendra Avatar asked Jan 10 '11 12:01

Hitendra


1 Answers

Instead of intercepting the TouchEvent with an overlay you can set an OnMapClickListener directly on the GoogleMap object.

googleMap.setOnMapClickListener(new OnMapClickListener(){
        void onMapClick(LatLng point){
            Toast.makeText(getContext(),
                point.latitude + ", " + point.longitude,
                Toast.LENGTH_SHORT).show();
        }
    });

How to get the GoogleMap Object from a MapFragment or a MapView see https://developers.google.com/maps/documentation/android/map#add_map_code

like image 91
David Boho Avatar answered Nov 15 '22 12:11

David Boho