King Luy
King Luy

Reputation: 141

Android Google Maps API v2 onInfoWindowClick triggers on create of activity all listeners

Hi i have a map with a lot of markers. When i add the markers to the map i want to add an onInfoWindowClick Listener to each marker with individual data. I want to load an activety with informations of the marker with the onInfoWindowClick Listener.

The code do not work correct. When the activety is created all the listeners are triggered at the same time and when i click on the infoWindow nothing happens.

private void addMarkerToMap(double lat, double lng, String eventTitle,
            String eventDiscribtion) {
        Marker currentMarker = myMap.addMarker(new MarkerOptions()
                .position(new LatLng(lat, lng)).title(eventTitle)
                .snippet(eventDiscribtion));

        onInfoWindowClick(currentMarker);
    }

    @Override
    public void onInfoWindowClick(Marker marker) {

            Intent nextScreen = new Intent(MapsActivity.this,
                    EventActivity.class);
            nextScreen.putExtra("userId", "" + userId);
            nextScreen.putExtra("eventId", "" + eventId);

            startActivityForResult(nextScreen, 0);

    }

Upvotes: 1

Views: 8278

Answers (2)

dumazy
dumazy

Reputation: 14435

check out this post about how to associate information or objects to markers: http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html

Upvotes: 2

RorschachDev
RorschachDev

Reputation: 354

You would implement the onclick behavior within your GoogleMap Object (myMap)

myMap.setOnInfoWindowClickListener(
  new OnInfoWindowClickListener(){
    public void onInfoWindowClick(Marker marker){
      Intent nextScreen = new Intent(MapsActivity.this,EventActivity.class);
        nextScreen.putExtra("userId", "" + userId);
        nextScreen.putExtra("eventId", "" + eventId);

        startActivityForResult(nextScreen, 0);
    }
  }
)

Upvotes: 7

Related Questions