onInfoWindowCLick 表示它从未使用过。请帮帮我
public class MapsActivity extends FragmentActivity {
private GoogleMap mMap; // Might be null if Google Play services APK is not available.
private Map<Marker, Class> allMarkersMap = new HashMap<Marker, Class>;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Marker marker1 = mMap.addMarker(new MarkerOptions()
.position(new LatLng(0, -0))
.title("Netherlands")
.snippet("Amsterdam"));
allMarkersMap.put(marker1, MainActivity.class);
public void onInfoWindowClick(Marker marker1) {
Class cls = allMarkersMap.get(marker1);
Intent intent = new Intent(MapsActivity.this, cls);
startActivity(intent);
}
}
答案 0 :(得分:1)
将此添加到您的代码
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MapsActivity.this,OtherActivity.class);
startActivity(intent);
}
});
答案 1 :(得分:0)
为多个标记尝试此解决方案
ArrayList<MarkerData> markersArray = new ArrayList<MarkerData>();
for(int i = 0 ; i < markersArray.size() ; i++ ) {
createMarker(markersArray.get(i).getLatitude(), markersArray.get(i).getLongitude(), markersArray.get(i).getTitle(), markersArray.get(i).getSnippet(), markersArray.get(i).getIconResID());
}
...
protected void createMarker(double latitude, double longitude, String title, String snippet, int iconResID) {
return googleMap.addMarker(new MarkerOptions()
.position(new LatLng(latitude, longitude))
.anchor(0.5f, 0.5f)
.title(title)
.snippet(snippet);
.icon(BitmapDescriptorFactory.fromResource(iconResID)));
}