简体   繁体   English

如何从标记列表中提取标记信息

[英]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. 我正在使用以下代码在mapfragment中使用三个数组创建标记列表,这三个数组发送一个记录列表的纬度,经度和名称信息。 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 您可以在以下网址找到它: http//bon-app-etit.blogspot.be/2012/12/add-informationobject-to-marker-in.html

Every marker has got an Id. 每个标记都有一个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 如果您存储该ID,以及您需要的信息,您可以获得正确的信息

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);

        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何单击地图上多个标记中的一个标记,然后转到包含标记信息的活动 - How to click a marker from multiple markers on a map and then go to a activity with info of the markers 如何从标记列表中将特定标记置于中心 - how to put particular marker in center from list of markers 集群标记后,osmdroid标记信息窗口不显示 - osmdroid marker info window dont show after clustering markers 如果有多个标记,则oninfowindowclick仅与标记信息一起使用 - oninfowindowclick used only with only marker info in case of multiple markers 标记信息窗口中的意图 - intent from marker info window cordova-plugin-googlemaps如何从标记数组触发标记的info_window - cordova-plugin-googlemaps how to trigger the info_window of marker from marker array 如何在GoogleMaps中更新标记并识别标记位置 - How to Update Marker And Indentify Markers Positions In GoogleMaps 每当用户更改Google Map Android中的位置时,如何检查用户是否处于标记之一(从10000个标记中)? - How to check if user in one of marker (from 10000 of markers) everytime user change location in google map android? android mapbox:我如何为标记设置动画,例如标记从屏幕顶部掉落? - android mapbox: how can i animate markers, like marker falling from the top of screen? 点击地图上的标记时如何显示信息窗口? - How to show an info window on tapping a marker on map?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM