MarkerOnClick数据为空

时间:2019-05-20 12:04:32

标签: android google-maps

我正在按照以下步骤设置标记,并且能够在地图上看到标记

 if (googleMap != null && mapFragment != null && googleMap.getProjection() != null) {
                                    googleMap.addMarker(new MarkerOptions().position(new LatLng(
                                            Double.parseDouble(storesWithDistance.getLatitude() + ""), Double.parseDouble(storesWithDistance.getLongitude() + "")
                                    )).title(storesWithDistance.getStoreName() + "").snippet(i + ""));
                                }

`marker.getTitle()` is returning `null` ..... Why is it happening ?

@Override
    public boolean onMarkerClick(Marker marker) {
        try {
            if (googleMap != null && mapFragment != null && googleMap.getProjection() != null) {

                String title = marker.getTitle();
                String snippet = marker.getSnippet();

                Log.d("","");
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return true;
    }

1 个答案:

答案 0 :(得分:1)

您是否实现了 GoogleMap.OnMarkerClickListener 接口? 您是否添加了这一行? :

googleMap.setOnMarkerClickListener(this)

如果您尝试将String title = marker.getTitle(); try..catch 块中取出并用Log.d()测试,该怎么办?