I am looking for a proper touch event that will be triggered when user touches the map (Google Maps Android API). Does anyone have an idea as to how to do it ?
Asked
Active
Viewed 6,886 times
9
-
10http://stackoverflow.com/questions/14013002/google-maps-android-api-v2-detect-touch-on-map – Angel Koh Dec 15 '15 at 04:39
2 Answers
11
You can directly add click listener and get position of touch on Map in form of Location.
map.setOnMapClickListener(new GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng latLng) {
//Do what you want on obtained latLng
}
});
![](../../users/profiles/3726793.webp)
Arth Tilva
- 2,447
- 19
- 39
2
You should use SetOnMapClickListener. Hope below demo code will help you to do so.
googleMap.setOnMapClickListener(new GoogleMap.OnMapClickListener()
{
@Override
public void onMapClick (LatLng latLng){
latitude = latLng.latitude;
longitude = latLng.longitude;
myMarker = googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)));
}
});
![](../../users/profiles/5501887.webp)
Gaurav Balbhadra
- 154
- 10