【发布时间】:2015-11-12 04:45:05
【问题描述】:
我想创建一个应用程序,它可以从数据库接收一组点并为地图上的每个点添加标记。我目前正在使用对象数组进行测试。我在循环中使用了相同的标记变量来将标记放在地图上。
包含我的标记位置的数组还包含一些关于我希望在触摸标记时在自定义信息窗口(从数组中获取数据)中显示的特定位置的其他数据。
我不确定在调用此信息窗口时应该如何区分不同的标记。
OnMarkerClickListener document on developers.google.com
我添加标记的代码:
for (pointNumber= 0; pointNumber<pointArray.length; pointNumber++) {
taxiLatitude = pointArray[pointNumber].position.latitude;
taxiLongitude = pointArray[pointNumber].position.longitude;
if (valueInArray<someValue) {
pointMarker = mMap.addMarker(new MarkerOptions()
.position(new LatLng(pointArray[pointNumber].position.latitude, carsArray[pointNumber].position.longitude))
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN))
.title("Title: "+pointArray[pointNumber].pointTitle)
.snippet("Snippet: "+pointArray[pointNumber].pointSnippet));
} else {
System.out.println("Out of range");
}
}
我将数据添加到自定义信息窗口的代码,我得到了here
class CustomWindowAdapter implements GoogleMap.InfoWindowAdapter {
LayoutInflater mInflater;
public CustomWindowAdapter(LayoutInflater i){
mInflater = i;
}
@Override
public View getInfoContents(Marker marker) {
// Getting view from the layout file
View v = mInflater.inflate(R.layout.custom_window_layout, null);
// Populate fields
ImageView image = (ImageView) v.findViewById(R.id.image);
image.setImageResource(pointArray[pointNumber].image);
TextView title = (TextView) v.findViewById(R.id.tv_1);
title.setText(pointArray[pointNumber].text1);
TextView description = (TextView) v.findViewById(R.id.text_2);
description.setText(pointArray[pointNumber].text2);
}
// Return info window contents
return v;
@Override
public View getInfoWindow(Marker marker) {
return null;
}
}
【问题讨论】:
-
这可能会有所帮助,请使用 HashMap:stackoverflow.com/a/30602617
标签: android google-maps google-maps-api-2