我想知道如何设置"OnClick"为标记在谷歌地图在android。
示例:用户触摸标记,我的应用程序检测到这个
My marker
@Override
public void onMapReady(GoogleMap map) {
map.moveCamera(CameraUpdateFactory.newLatLngZoom(
new LatLng(-18.142, 178.431), 2));
map.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
map.setMyLocationEnabled(true);
mUiSettings = map.getUiSettings();
mUiSettings.setZoomControlsEnabled(true);
LatLng sydney = new LatLng(-33.867, 151.206);
map.setMyLocationEnabled(true);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(sydney, 13));
map.addMarker(new MarkerOptions()
.title("Sydney")
.snippet("The most populous city in Australia.")
.position(sydney));
}
尝试使用OnMarkerClickListener
,如下所示:
map.setOnMarkerClickListener(new OnMarkerClickListener(){
@Override
public boolean onMarkerClick(Marker arg0) {
// do your stuff
return true;
}});
implement OnMarkerClickListener
public class MarkerDemoActivity extends android.support.v4.app.FragmentActivity
implements OnMarkerClickListener
{
private Marker myMarker;
myMarker = googleMap.addMarker();
}
@Override
public boolean onMarkerClick(final Marker marker) {
if (marker.equals(myMarker))
{
//handle click here
}
}
}
示例
this.googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker arg0) {
Log.d(TAG, arg0.getTitle() + " | " + arg0.getPosition().toString());
return false;
}
});