Reputation: 7281
I want to detect two scenario 1. when a user tap into a google map 2. when a user release that tap from the map It's like the touchevent which we use for other view like TextView, Linearlayout etc... -Thank you enter image description here
Upvotes: 1
Views: 837
Reputation: 4005
You can create some kind of overlay over MapFragment
and set onTouchListener
to it.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/map"
class="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<View
android:id="@+id/mapOverlay"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</RelativeLayout>
Java code:
View mapOverlay = (View) findViewById(R.id.mapOverlay);
mapOverlay.setOnTouchListener(new View.OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
// handle tap
break;
case MotionEvent.ACTION_UP:
// handlerelease
break;
}
return false; // return false if you want propagate click to map
}
});
Upvotes: 1
Reputation: 6704
For the first scenario, use this. To get it working is pretty much self explanatory but here is an example for your convenience.
gMap.setOnMapClickListener(new OnMapClickListener() {
@Override
public void onMapClick(LatLng arg0) {
// TODO Auto-generated method stub
Log.d("LatLng", arg0.latitude + "-" + arg0.longitude);
}
});
Upvotes: 0