首页 > 解决方案 > MarkerOnClick 数据为空

问题描述

我正在设置标记如下,我可以在地图上看到标记

 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;
    }

标签: androidgoogle-maps

解决方案


你实现了接口GoogleMap.OnMarkerClickListener吗?你添加了这一行吗?:

googleMap.setOnMarkerClickListener(this)

如果你试图把你String title = marker.getTitle();try..catch块放在外面并用 Log.d() 测试它怎么办?


推荐阅读