I've been searching for help on implementing OnMarkerClickListener but nothing I've found has worked. This is my marker below and when clicked it only changes colour(light blue). I'm looking for it to open a bigger window so I can put in more info. Is this possible?
googlemap.addMarker(new MarkerOptions()
.position(new LatLng(49.378,-0.3904))
.title("Hello World")
.snippet("This is my test app")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
The marker works fine above on my Map but now I would like to click on the marker and for it to open a new activity/page or a bigger window, what ever is easier to work with. As I am a real novice at making apps, If anyone who has successfully got a working example please could you put up a link or some code.
Thanks in advance!
Edit:
From the tutorial that was suggested I have changed some of the MainActivity.java.
I've added in OnMarkerClickListener and have chosen to add unimplemented methods to the Public Class
public class MainActivity extends Activity implements LocationListener, OnMarkerClickListener {
Underneath private void setUpMap() I have added to my code: private Marker myMarker, the setonMarkerclick listener and myMarker =, :
private Marker myMarker;
{
googlemap.setOnMarkerClickListener(this);
myMarker = googlemap.addMarker(new MarkerOptions()
.position(new LatLng(LatLng))
.title("Hello World")
.snippet("My First App")
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_ORANGE)));
}
In the unimplemented method at the bottom I have:
@Override
public boolean onMarkerClick(Marker arg0) {
// TODO Auto-generated method stub
return false;
What do I need to change in the public Boolean OnMarkerClick part? I'm not getting any errors but its just not working. What else do I have to add in or change?
Any help is appreciated!
Marker click events
Don't snap to marker after click in android map v2
Quoting from the above post
You can use an OnMarkerClickListener
to listen for click events on the marker. To set this listener on the map, call GoogleMap.setOnMarkerClickListener(OnMarkerClickListener). When a user clicks on a marker, onMarkerClick(Marker) will be called and the marker will be passed through as an argument. This method returns a boolean that indicates whether you have consumed the event (i.e., you want to suppress the default behavior). If it returns false, then the default behavior will occur in addition to your custom behavior. The default behavior for a marker click event is to show its info window (if available) and move the camera such that the marker is centered on the map.
Use OnMarkerClickListener on your marker.
Check the link for code snippets
Google Maps API v2: How to make markers clickable?
Example: Works on my phone
Marker source, destination; GoogleMap mMap; mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); source = mMap.addMarker(new MarkerOptions() .position(sc) .title("MyHome") .snippet("Bangalore") .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin))); destination = mMap.addMarker(new MarkerOptions() .position(lng) .title("MapleBear Head Office") .snippet("Jayanager") .icon(BitmapDescriptorFactory.fromResource(R.drawable.pin))); mMap.setOnMarkerClickListener(marker -> { if (marker.getTitle().equals("MyHome")) // if marker source is clicked Toast.makeText(MainActivity.this, marker.getTitle(), Toast.LENGTH_SHORT).show();// display toast return true; });