Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在Google地图集群中为标记添加标题_Android_Google Maps_Google Maps Markers - Fatal编程技术网

Android 在Google地图集群中为标记添加标题

Android 在Google地图集群中为标记添加标题,android,google-maps,google-maps-markers,Android,Google Maps,Google Maps Markers,我正在创建一个有数百个标记的应用程序,所以我决定实施集群是个好主意。但是,我遇到了为集群中的标记添加标题的问题。我需要这些数据,以便稍后在创建标记的信息窗口时从JSON检索项目。总结一下,我的问题是,如何为集群中的每个标记添加一个字符串作为标题 我当前的代码: public class MyItem implements ClusterItem { private final LatLng mPosition; public MyItem(double lat, double

我正在创建一个有数百个标记的应用程序,所以我决定实施集群是个好主意。但是,我遇到了为集群中的标记添加标题的问题。我需要这些数据,以便稍后在创建标记的信息窗口时从JSON检索项目。总结一下,我的问题是,如何为集群中的每个标记添加一个字符串作为标题

我当前的代码:

public class MyItem implements ClusterItem {
    private final LatLng mPosition;

    public MyItem(double lat, double lng) {
        mPosition = new LatLng(lat, lng);
    }

    @Override
    public LatLng getPosition() {
        return mPosition;
    }
}

for (int i = 0; i < activity.m_jArry.length(); i++)
    {
        JSONObject j;
        try {
            j = activity.m_jArry.getJSONObject(i);
            mClusterManager.addItem(new MyItem(j.getDouble("lat"), j.getDouble("lon")));
            //mMap.addMarker(new MarkerOptions().title(j.getString("Unique")).snippet(i + "").position(new LatLng(j.getDouble("lat"), j.getDouble("lon"))));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }

感谢您的帮助:

有一个全局解决方案可帮助您添加标题、代码片段和图标,以便您获得所需内容

修改ClusterItem对象并添加3个变量:

public class MyItem implements ClusterItem {

private final LatLng mPosition;
BitmapDescriptor icon;
String title;
String snippet;

public MyItem(BitmapDescriptor ic,Double lat , Double lng,String tit ,String sni)
{
    mPosition = new LatLng(lat,lng);
    icon = ic;
    title = tit;
    snippet = sni;

}
创建服装渲染后:

public class OwnRendring extends DefaultClusterRenderer<MyItem> {

    public OwnRendring(Context context, GoogleMap map,
                           ClusterManager<MyItem> clusterManager) {
        super(context, map, clusterManager);
    }


    protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {

        markerOptions.icon(item.getIcon());
        markerOptions.snippet(item.getSnippet());
        markerOptions.title(item.getTitle());
        super.onBeforeClusterItemRendered(item, markerOptions);
    }
}

有一个全局解决方案可以帮助您添加标题、代码片段和图标,这样您就可以得到想要的东西

修改ClusterItem对象并添加3个变量:

public class MyItem implements ClusterItem {

private final LatLng mPosition;
BitmapDescriptor icon;
String title;
String snippet;

public MyItem(BitmapDescriptor ic,Double lat , Double lng,String tit ,String sni)
{
    mPosition = new LatLng(lat,lng);
    icon = ic;
    title = tit;
    snippet = sni;

}
创建服装渲染后:

public class OwnRendring extends DefaultClusterRenderer<MyItem> {

    public OwnRendring(Context context, GoogleMap map,
                           ClusterManager<MyItem> clusterManager) {
        super(context, map, clusterManager);
    }


    protected void onBeforeClusterItemRendered(MyItem item, MarkerOptions markerOptions) {

        markerOptions.icon(item.getIcon());
        markerOptions.snippet(item.getSnippet());
        markerOptions.title(item.getTitle());
        super.onBeforeClusterItemRendered(item, markerOptions);
    }
}

您好,我关注了您的问题和答案,但当单击集群项目时,我无法显示实际的信息窗口。有什么建议吗?嗨,我听了你的问题和答案,但当点击一个集群项目时,我被困在显示实际的信息窗口。有什么建议吗?