【问题标题】:how to add infoWindowAdapters for multiple markers having different values?如何为具有不同值的多个标记添加 infoWindowAdapters?
【发布时间】:2019-10-16 10:30:34
【问题描述】:
 Marker drMark=mMap.addMarker(new MarkerOptions().position(drLoc).title("Lahore").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
 Marker selfMark=mMap.addMarker(new MarkerOptions().position(curLocation).title("Lahore").icon(BitmapDescriptorFactory.fromResource(R.drawable.passengermarker)));

我正在尝试将 infoWindow 添加到地图活动中的多个标记。但是 infoWindow 适配器在 onMapsReady 中初始化后在所有标记上显示相同的数据。我想在所有带有自己信息的标记上显示 infoWindow,即要单独初始化标记 infoWindows,以便数据变得相关。

【问题讨论】:

  • 请阅读“如何创建minimal reproducible example”。然后使用edit 链接改进您的问题(不要通过 cmets 添加更多信息)。否则我们无法回答您的问题并为您提供帮助。
  • 它得到了替换给我片刻
  • 请查看@GhostCat

标签: java android marker infowindow


【解决方案1】:

一种方法是使用标记标记来区分 infoWindowAdapter 部分中的标记。我认为这是完成这项工作的一种更简单的方法。

selfMark=mMap.addMarker(new MarkerOptions().position(curLocation).title("Lahore").icon(BitmapDescriptorFactory.fromResource(R.drawable.passengermarker)));
                selfMark.setTag("user");

 drMark=mMap.addMarker(new MarkerOptions().position(drLoc).title("Lahore").icon(BitmapDescriptorFactory.fromResource(R.drawable.marker)));
                    drMark.setTag("driver");

InfoWinfoAdapter 的这一部分:

     mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
                            @Override
                            public View getInfoWindow(Marker marker) {
                                return null;
                            }

                                @Override
                                public View getInfoContents(final Marker marker) {
                                View view = getLayoutInflater().inflate(R.layout.driver_inf, null);

                                final TextView tvEmail = view.findViewById(R.id.emailDrive);
                                final TextView tvname = view.findViewById(R.id.nameDrive);
                                final TextView tvlocality = view.findViewById(R.id.localityDrive);
                                    if(marker.getTag().equals("driver")){
                                        tvEmail.setText("Driver");
                                    }
                                    else if (marker.getTag().equals("user")){
                                        tvEmail.setText("Passenger");
                                    }


                                tvname.setText(dC.getName());
                                Geocoder gc = new Geocoder(passengerAct.this, Locale.getDefault());
                                try {
                                    List<Address> adr = gc.getFromLocation(marker.getPosition().latitude, marker.getPosition().longitude, 1);
                                    Address address = adr.get(0);
                                    tvlocality.setText(address.getLocality() + "," + address.getCountryName());
                                } catch (IOException e) {
                                    e.printStackTrace();
                                }
                                return view;
                            }
                        });

【讨论】:

    猜你喜欢
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 2022-11-13
    • 2017-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多