连同标题和摘要一起如何向标记添加额外的数据? [英] Along with title and snippet how to add extra data to marker?

查看:212
本文介绍了连同标题和摘要一起如何向标记添加额外的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我的远程服务器为请求返回了10的多个值.我解析了我的响应并使用for循环在地图上添加了标记(此处我向标题和片段添加了信息)(此处我想向其中添加额外的数据)标记,以便我可以在信息窗口中单击事件中访问它)

Problem : My remote server returns 10 multiple value for a request.i parsed my response and using for loop i added markers(here i added info to title and snippet) on a map.(here i want to add extra data to marker so that i can access it in on info window click event)

在infoWindowClickListener中,我想访问这些额外的数据.

in infoWindowClickListener i want to access that extra data.

如何向标记添加额外的数据/如何为特定的标记单击访问ph数据(否则,我将获得所有标记中ph的最后一个值).

How to add extra data to marker/ how to access ph data for a particular marker click(other wise i will get last value of ph in all markers).

我这样尝试过.

   private class HttpGetTask extends AsyncTask<Void, Void, String> 
    {
    //URL and http stuff
    }

            @Override
            protected void onPostExecute(String result) {

                try {
                     json = new JSONArray(result);

                    for (int i = 0; i < json.length(); i++) {
                        Log.v("Response", result);
                        final JSONObject e = json.getJSONObject(i);
                        String point = e.getString("point");

                        Log.v("POINT", point);//Checking points

                        String phone1 = e.getString("ph");
                        Log.v("PH", phone1);//Checking phone numbers

                        String[] point2 = point.split(",");//Splitting points
                        double lat1 = Double.parseDouble(point2[0]);
                        double lng1 = Double.parseDouble(point2[1]);
                        Log.v("LLDN", "" + lat1 + "&" + lng1);

                        //Adding multiple markers
//can i add extra information here along with title and snippet
                        gMap.addMarker(new MarkerOptions()
                                .title(e.getString("name"))
                                .snippet(
                                        e.getString("LS")+""+e.getString("ph") )
                                .position(new LatLng(lng1, lat1))
                                .icon(BitmapDescriptorFactory
                                        .fromResource(R.drawable.pmr)));

                    }
                } catch (JSONException e)
                {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

是否可以为标记附加附加值以及标题和摘要. 还是我以错误的方式解析??

is it possible to attach extra value to a marker, along with title and snippet.? or am i parsing in wrong way.?

推荐答案

这不是最好的解决方案,但这是我在应用程序中所做的事情.

Not the best solution but this what I do in my application.

在活动/片段中将markersMap创建为私有字段.

create markersMap as a private field in your activity/fragment.

private Map<Marker, ExtraDataObj> markersMap = new HashMap<Marker, ExtraDataObj>();

生成标记时,还将标记和其他数据放入markersMap

When you generate marker also put the marker and extra data in your markersMap

ExtraDataObj extraDataObj = new ExtraDataObj();
// extract and store all data you want in the extraDataObj
....
...
..
Marker marker = gMap.addMarker(new MarkerOptions()
                        .title(e.getString("name"))
                        .snippet(
                                e.getString("LS")+""+e.getString("ph") )
                        .position(new LatLng(lng1, lat1))
                        .icon(BitmapDescriptorFactory
                                .fromResource(R.drawable.pmr)));
markersMap.put(marker, extraDataObj);

在您的onInfoWindowClick中,从markersMap获得额外的数据

in your onInfoWindowClick get extra data from the markersMap

ExtraDataObj extraDataObj = markersMap.get(arg0) 

这篇关于连同标题和摘要一起如何向标记添加额外的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆