简体   繁体   中英

How to extract a marker info from a list of markers

I'm using the following code to create a list of markers in a mapfragment using three arrays that sends the information of latitude, longitude and name of one list of records. My objective is to get send to a new intent the name of the record when the info window is clicked. Now sends for all markers the recordname of the last item of the array but I need send the specific info to each marker. Any idea?

            String[] arraylatitud = arrlat.toArray(new String[arrlat.size()]);
            String[] arraylongitud = arrlon.toArray(new String[arrlon.size()]);
            String[] arrayrecordname = arrrecname.toArray(new String[arrrecname.size()]);

            for(int i=0; i<arrlon.size();i++){


                     mapa.addMarker(new MarkerOptions()
                    .position(new LatLng(Float.valueOf (arraylatitud[i]),Float.valueOf (arraylongitud[i])))
                    .title("Grabación:" + arrayrecordname[i])
                    .snippet("Latitud:" + arraylatitud[i] + "Longitud:" + arraylongitud[i]));

                    filename = arrayrecordname[i];

            } 

            mapa.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

                    public void onInfoWindowClick(Marker marker) {


                           Intent intent = new Intent(MapArea.this, StreamingArea.class);
                           intent.putExtra("variable_selection", filename.toString());
                           startActivity(intent);


                    }
            }

I've just made a blog post on this. You can find it at: http://bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html

Every marker has got an Id.

Marker m = mapa.addMarker(new MarkerOptions()
                .position(new LatLng(Float.valueOf (arraylatitud[i]),Float.valueOf (arraylongitud[i])))
                .title("Grabación:" + arrayrecordname[i])
                .snippet("Latitud:" + arraylatitud[i] + "Longitud:" + arraylongitud[i]));

m.getId();

if you store that id, along with the information you need you can get the right info back

getMap().setOnInfoWindowClickListener(new OnInfoWindowClickListener() {

        public void onInfoWindowClick(Marker marker) {
            int id = marker.getId();
            Intent i = new Intent(MapArea.this.getActivity(), StreamingArea.class);
            //your code goes here
            i.putExtra(....);

            startActivity(i);

        }
    });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM