我想在用户点击谷歌地图上的标记时启动一项新活动。但是我在功能oninfowindowclicklistener上遇到了一些问题..我在地图上做了几个标记,我想点击它... < / p>
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
setUpMapIfNeeded();
}
mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker){
Intent intent = new Intent(MapsActivity.this, form.class);
startActivity(intent);
})
}
@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
}
private void setUpMapIfNeeded() {
// Do a null check to confirm that we have not already instantiated the map.
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map))
.getMap();
// Check if we were successful in obtaining the map.
if (mMap != null) {
setUpMap();
}
}
}
private void setUpMap() {
mMap.addMarker(new MarkerOptions().position(new LatLng(6.440978, 100.200227)).title("Balai Bomba dan Penyelamat Kangar"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.445473, 100.255613)).title("Balai Bomba dan Penyelamat Arau"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.427578, 100.278783)).title("Balai Bomba dan Penyelamat Pauh"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.659915, 100.323910)).title("Balai Bomba dan Penyelamat Padang Besar"));
mMap.addMarker(new MarkerOptions().position(new LatLng(6.412559, 100.190950)).title("Balai Bomba dan Penyelamat Kuala Perlis"));
mMap.setMyLocationEnabled(true);
}
}
答案 0 :(得分:0)
标记是
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Log.e("map marker", "marker is " + marker.getTitle());
return false;
}
});