[英]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.