I have a code so that a single marker starts an action when you click on infowindow. It works absolutely fine. But when I try to add another @override to another marker, it always opens the last class in all Markers windows. Thus, in fact, all infowindows tokens open the same activity when pressed, and do not open the separate class that I intended to do this.
This is the code below that successfully opens 1 activity in InfoWindowClicked. I called it example.class, this is for everyone who needs this example.
public class MainActivity extends Activity implements OnInfoWindowClickListener { private GoogleMap googlemap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if(isGooglePlay()){ setContentView(R.layout.activity_main); setUpMap(); { } } googlemap.addMarker(new MarkerOptions() .position(new LatLng(0,-0)) .title("Title") .snippet("Snippet") .icon(BitmapDescriptorFactory.fromResource(R.drawable.star))); googlemap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { Intent intent = new Intent(MainActivity.this,Example.class); startActivity(intent); } }); {
So, under googlemap googlemap / mMap (or whatever you call) and @override void Oncreate (my application only starts if the GooglePlayServices application is available like this) you can put the marker and code infowindowclick.
Make sure that somewhere in the code there is also (usually in private void setUpMap () {)
googlemap = ((MapFragment)getFragmentManager().findFragmentById(R.id.map)).getMap();
Now below is the code with two markers, but both of them open example2.class when clicked. Can someone help me figure this out so that I can separate them and open different classes for them?
googlemap.addMarker(new MarkerOptions() .position(new LatLng(0,-0)) .title("Title") .snippet("Snippet") .icon(BitmapDescriptorFactory.fromResource(R.drawable.star))); googlemap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { Intent intent = new Intent(MainActivity.this,Example.class); startActivity(intent); } }); { { googlemap.addMarker(new MarkerOptions() .position(new LatLng( 0, -0)) .title("Title") .snippet("Snippet") .icon(BitmapDescriptorFactory.fromResource(R.drawable.star))); googlemap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { @Override public void onInfoWindowClick(Marker marker) { Intent intent = new Intent(MainActivity.this,Example2.class); startActivity(intent); } }); }} }
Edit (07/06/2013):
private GoogleMap googlemap; private Map<Marker, Class> allMarkersMap = new HashMap<Marker, Class>();
The above applies to class level ^^^
Marker marker1 = googlemap.addMarker(new MarkerOptions() .position(new LatLng(0,0)) .title("England") .snippet("London") .icon(BitmapDescriptorFactory.fromResource(R.drawable.star))); allMarkersMap.put(marker1, Contact.class); } public void onInfoWindowClick(Marker marker) { Class cls = allMarkersMap.get(marker); Intent intent = new Intent(MainActivity.this, cls); startActivity(intent); }
The above ^^^^ is under my "protected void onCreate (Bundle savedInstanceState) {". There are no errors when I debug, I see a marker, but I can not click on InfoWindow. Warnings:
Class is a raw type. References to generic type Class<T> should be parameterized
I see this warning twice at the class level and once in public void onInfoWindowClick on the word "Class" . I tried several different things, such as “Add argument types to“ Class ”, but that didn’t work. In Marker-Marker in a public void, I changed the marker on marker1 and on the line below allMarkersMap.get (marker); changed (marker) to (marker1) just for a try, but that didn't work. Is there anything else I can do to try to initialize the onInfoWindowClick function?