gpt4 book ai didi

java - 在谷歌标记 Android 上更新 InfoWindowAdapter 中的内容

转载 作者:行者123 更新时间:2023-11-30 11:22:06 25 4
gpt4 key购买 nike

我正在尝试在 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;

}
}

负责向 map 添加点的代码:

    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 类无法从名称变量中获取正确的值。任何人都知道如何解决这个问题?我认为我所说的和我解释的方式是可以理解的,但如果不是,请告诉我,我会回答。

谢谢

最佳答案

首先将你的 Map.setInfoWindowAdapter(new poisInfoWindowAdapter()); 放在你的 for 循环之外 onPostExecute(....)

然后像下面这样实现你的 poisInfoWindowAdapter():

 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(marker.getTitle());

TextView t2 = (TextView)InfoPopupLayout.findViewById(R.id.title2);
t2.setText(marker.getSnippet());

return InfoPopupLayout;
}
}

更新:设置Marker

Currnt = mMap.addMarker(new MarkerOptions()
.icon(BitmapDescriptorFactory.fromResource(R.drawable.mark_red))
.position(new LatLng(latitude,longitude)
.title(locations)
.snippet(city));

关于java - 在谷歌标记 Android 上更新 InfoWindowAdapter 中的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21907597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com