使用JSON映射多个标记

时间:2016-07-16 05:23:49

标签: android json google-maps for-loop

嗨朋友我正在谷歌地图上工作,尝试使用JSON动态添加标记,但我能够先添加两个标记,最后一个我使用for循环请帮帮我

Json回复

{"status":"Success","locations":[{"id":"2","hotel_name":"Igloo","address":"CMM Court Complex S.O","latitude":"12.9765944","longitude":"77.5992708"},{"id":"3","hotel_name":"The Park","address":"CMM Court Complex S.O","latitude":"12.9765944","longitude":"77.5992708"},{"id":"5","hotel_name":"Pai viceroy","address":"Kadugodi Extention SO","latitude":"12.9967012","longitude":"77.758197"},{"id":"8","hotel_name":"Prominere","address":"EPIP S.O","latitude":"12.9698066","longitude":"77.74996320000002"},{"id":"9","hotel_name":"Jaya","address":"Kadugodi Extention SO","latitude":"12.9967012","longitude":"77.758197"},{"id":"10","hotel_name":"Sitara","address":"Tavarekere S.O","latitude":"12.9342565","longitude":"77.60439930000007"},{"id":"11","hotel_name":"Loyalty","address":"Chandapura S.O","latitude":"12.8016","longitude":"77.7041"},{"id":"12","hotel_name":"Daspalla","address":"Ullalu Upanagar S.O","latitude":"1.370527","longitude":"103.83727999999996"}]}

我的代码

private void mapsmethod() {
        Display.showLoadingDialog(getActivity(), "Loading Locations");
        String mapsurls = Jsonurl.url + "map_locations.php?city=" + Session.getcityname(getActivity());
        Display.log(mapsurls);
        JsonObjectRequest mapsreq = new JsonObjectRequest(Request.Method.GET, mapsurls, null, new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                try {
                    JSONArray mapsarray = response.getJSONArray("locations");
//                    List<Marker> markers=new ArrayList<Marker>();
                    for (int i = 0; i < mapsarray.length(); i++) {
                        JSONObject mapsmarkerobj = mapsarray.getJSONObject(i);


                       /* MarkerOptions m = new MarkerOptions()
                                .title(mapsmarkerobj.optString("hotel_name"))
                                .position(new LatLng(mapsmarkerobj.optDouble("latitude"), mapsmarkerobj.optDouble("longitude")));
                        bottomap.addMarker(m);*/
                        /*long latitudemarker=mapsmarkerobj.getLong("latitude");
                        long longmarker=mapsmarkerobj.getLong("longitude");*/
                        /*Marker marker = bottomap.addMarker(new MarkerOptions().position(new LatLng(mapsmarkerobj.getLong("latitude"),mapsmarkerobj.getLong("longitude"))).title(mapsmarkerobj.getString("hotel_name")));
                        markers.add(marker);*/
                    }
//                    markers.size();
//                    Display.log(String.valueOf(markers.size()));

                } catch (JSONException e) {
                    e.printStackTrace();
                }
                Display.hideLoadingDialog();
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                Display.log(error.toString());
                Display.hideLoadingDialog();
            }
        });
        mapsreq.setRetryPolicy(new DefaultRetryPolicy(500000, DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
        AppController.getInstance().addToRequestQueue(mapsreq);
    }

0 个答案:

没有答案