google 地图中 android 的标记
Marker in google maps for android
我想知道如何为 google 上的 marker 设置“OnClick” android.
中的地图
示例:用户触摸标记,我的应用程序检测到这一点。
我的标记
@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));
}
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
}
}
}
尝试使用 OnMarkerClickListener
,如下所示:
map.setOnMarkerClickListener(new OnMarkerClickListener(){
@Override
public boolean onMarkerClick(Marker arg0) {
// do your stuff
return true;
}});
示例
this.googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker arg0) {
Log.d(TAG, arg0.getTitle() + " | " + arg0.getPosition().toString());
return false;
}
});
我想知道如何为 google 上的 marker 设置“OnClick” android.
中的地图示例:用户触摸标记,我的应用程序检测到这一点。
我的标记
@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));
}
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
}
}
}
尝试使用 OnMarkerClickListener
,如下所示:
map.setOnMarkerClickListener(new OnMarkerClickListener(){
@Override
public boolean onMarkerClick(Marker arg0) {
// do your stuff
return true;
}});
示例
this.googleMap.setOnMarkerClickListener(new OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker arg0) {
Log.d(TAG, arg0.getTitle() + " | " + arg0.getPosition().toString());
return false;
}
});