I have seen that people are finding a lot of difficulties with this specific task and I am in need of help as well.
I have successfully created Markers on a Map using the default code that Google has provided. But now I want to be able to click on "InfoWindow" to open a new activity so I can add more information.
From this basic marker with Title and Snippet:
http://mobisys.in/blog/wp-content/uploads/2013/04/Screenshot_2013-04-04-17-19-581.png
Then to click on it and open a blank activity:
http://tuts-authors.s3.amazonaws.com/mobile.tutsplus.com/Shane%20Conder%20and%20Lauren%20Darcey/2012/09/25/Android-Creating-Hello-Worlds_Emulator-basic-hello-world.png
Does anyone know the best way to do this?
If you can answer this please put up some code or an example. Any help would be much appreciated!
Long press the marker to enable dragging. When you take your finger off the screen, the marker will remain in that position. Markers are not draggable by default. You must explicitly set the marker to be draggable either with MarkerOptions.
add this to your code
Mymap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
@Override
public void onInfoWindowClick(Marker marker) {
Intent intent = new Intent(MapActivity.this,OtherActivity.class);
startActivity(intent);
}
});
This method works even well with multiple markers. get the title of the marker using marker.getTitle() and Starts the activity based on which marker you clicked.
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng chennai = new LatLng(12.9671, 80.2593);
mMap.addMarker(new MarkerOptions().position(chennai).title("Chennai"));
LatLng perungudi = new LatLng(12.97, 80.25);
mMap.addMarker(new MarkerOptions().position(perungudi).title("Perungudi"));
LatLng pallikarnai = new LatLng(12.9377, 80.2154);
mMap.addMarker(new MarkerOptions().position(pallikarnai).title("Pallikarnai"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(chennai,12));
mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
if (marker.getTitle().equals("Chennai")){
Toast.makeText(MapsActivity.this, "Clicked"+marker.getTitle(), Toast.LENGTH_SHORT).show();
}
return false;
}
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With