Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Google Maps v2 - Add object to marker

Tags:

How can we add an object to a marker in the new Google Maps Android API v2? So if we click on the InfoWindow, we can do something with the object?

public void addSpotOnMap(Spot spot) {     getMap().addMarker(new MarkerOptions()             .position(new LatLng(spot.getParseGeoPoint().getLatitude(), spot.getParseGeoPoint().getLongitude()))             .title(spot.getName())             .snippet(spot.getCategory())             .draggable(false));  } 

This sets the location, title and snippet for the object. But I want to be able to go to another activity about this specific Spot-object if I click on the InfoWindow

like image 894
dumazy Avatar asked Dec 14 '12 18:12

dumazy


People also ask

How do I add a marker on Google Maps Android?

For adding a custom marker to Google Maps navigate to the app > res > drawable > Right-Click on it > New > Vector Assets and select the icon which we have to show on your Map. You can change the color according to our requirements. After creating this icon now we will move towards adding this marker to our Map.

What kind of object can you use to add one or more markers to a map?

You can use custom SVG vector paths to define the visual appearance of markers. To do this, pass a Symbol object literal with the desired path to the marker's icon property.


1 Answers

Not really sure if this is the correct answer, but take a look at this blogpost I made about this problem:

Since Marker is final, it's this can easily be solved by linking the data with the Marker in a Map, for example HashMap<Marker, YourDataClass> or HashMap<Marker, String>

Here's a tutorial that explains all: http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html

like image 182
dumazy Avatar answered Sep 21 '22 14:09

dumazy