【发布时间】:2014-03-21 09:12:33
【问题描述】:
我正在尝试在 google maps android 中使用自定义 InfoWindow 显示一些点(兴趣点)。我的问题是我不能将不同的信息放在不同的点上。我在更新弹出布局的 textview 内容时遇到问题。请参阅下面的示例代码。
我的 infoWindowAdapter 代码:
public class poisInfoWindowAdapter implements InfoWindowAdapter {
@Override
public View getInfoWindow(Marker arg) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
//Get Layout of POI's popups and assign values to text views.
View InfoPopupLayout = getLayoutInflater().inflate(R.layout.infopopup, null);
TextView t = ((TextView)InfoPopupLayout.findViewById(R.id.title));
t.setText(name);
return InfoPopupLayout;
}
}
负责将点添加到地图的代码:
public void onPostExecute(String responsePois) {
try {
JSONArray P = new JSONArray(responsePois);
for (int i = 0; i < P.length(); i++) {
JSONObject pois = P.getJSONObject(i);
position = new LatLng(pois.getDouble("y"), pois.getDouble("x"));
name = pois.getString("name_pt");
Map.setInfoWindowAdapter(new poisInfoWindowAdapter());
Map.addMarker(new MarkerOptions()
.position(position)
.title(name)
);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
在这种情况下,我的所有点都具有相同的名称。 infoWindowAdapter 类无法从 name 变量中获取正确的值。任何人都知道如何解决这个问题? 我认为我所说的和我的解释是可以理解的,但如果不是,请告诉我,我会回答。
谢谢
【问题讨论】:
-
嘿不明白。你有什么问题?
-
我的所有积分都同名。弹出布局有一个 TextView,它是一个在所有点上都获得相同值的标题。
-
把这个
Map.setInfoWindowAdapter(new poisInfoWindowAdapter());放到你的for循环外面试试。 -
现在仔细查看我的更新并检查您的
poisInfoWindowAdapter
标签: java android google-maps-markers infowindow