-1

I am using this code to draw markers on google map (hide the ones that are invisible on screen)

for (MyMapPointModel item : items) {
            // If the item is within the the bounds of the screen
            if (bounds.contains(item.getLatLng())) {
                // If the item isn't already being displayed
                if (!visibleMarkers.containsKey(item.getId())) {
                    // Add the Marker to the Map and keep track of it with
                    // the HashMap
                    // getMarkerForItem just returns a MarkerOptions object
                    customMarker = getMap().addMarker(getMarkerForItem(item));
                    visibleMarkers.put(item.getId(), customMarker);
                    drawMarker(item.getLatLng(), item.getThumbUri(), item.getId());
                }
            } else { // If the marker is off screen
                // If the course was previously on screen
                if (visibleMarkers.containsKey(item.getId())) {
                    // 1. Remove the Marker from the GoogleMap
                    visibleMarkers.get(item.getId()).remove();
                    // 2. Remove the reference to the Marker from the
                    // HashMap
                    visibleMarkers.remove(item.getId());

                }
            }
        }

and i am storing markers with items id in hashmap I want to call an activity with details for taped marker and i can't get item id from onMarkerClick listener (he provides only marker object). Am i missing something, and if i am what? Does anyone have a better idea?

M m
  • 53
  • 8

3 Answers3

1

and i am storing markers with items id in hashmap i am using hashmap

I assume that you are using that particular data structure successfully elsewhere and so it is useful.

For your problem, though, it sounds like that you need HashMap<String, Integer>, using getId() on Marker as the key. This will allow you to look up your Integer given its Marker.

Or, if you are creating your own info window, use the title or snippet fields in a Marker to hold a string representation of your integer, so you can use getTitle() or getSnippet() to retrieve that value directly.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
0

Try the below

 mMap.setOnMarkerClickListener(new OnMarkerClickListener()
                {

                    @Override
                    public boolean onMarkerClick(Marker arg0) {
                        arg0.getId() //get id
                        //use switch case
                        // or use title
                        if(arg0.getTitle().equals("title"))   
                        // do something
                        return true;
                    }

                });
Raghunandan
  • 132,755
  • 26
  • 225
  • 256
  • i am using hashmap , and my key value is of integer type, field id from database, i don't understand how can i get that value only with arg0(Marker)? – M m Sep 25 '13 at 16:21
  • no, i did not set one. Are you suggesting that i should set my marker title to id? – M m Sep 25 '13 at 16:24
  • @Mm then get the key using the map and use a switch case or if else – Raghunandan Sep 25 '13 at 16:26
0

use this code for that

 mMap.setOnMarkerClickListener(new OnMarkerClickListener()
            {

                @Override
                public boolean onMarkerClick(Marker arg0) {
                    if(arg0.getTitle().equals("MyHome")) // if marker source is clicked

                    return true;
                }

            });       
Shivang Trivedi
  • 2,182
  • 1
  • 20
  • 26