【问题标题】:update content in InfoWindowAdapter on google markers Android在谷歌标记 Android 上更新 InfoWindowAdapter 中的内容
【发布时间】: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


【解决方案1】:

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

第二次实现你的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));

【讨论】:

  • 谢谢,这可能有效,但问题是我有另一个内容要放,我无法从标题标记中获得。我在这里只放了例子的标题。我需要获取名称变量的内容。
  • @pdcc 当您当时点击任何标记时,此自定义窗口是使用获取该标记标题创建的
  • 你不懂我。我不仅需要获取名称变量,还需要从另一个变量中获取另一个值。我从这里删除以简化。
  • @sdcc 嘿,发生了什么事?
  • 谢谢...你给我一个想法..我在 sn-p 中传递我所有的变量内容,再次用“//”分隔,一旦进入类适配器,我就分开并放入 textviews...谢谢@MD
猜你喜欢
  • 2013-12-12
  • 2011-08-17
  • 2013-07-31
  • 2016-02-12
  • 2012-02-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-03-16
相关资源
最近更新 更多