自定义infowindow与凌空数据

时间:2016-04-11 07:07:35

标签: android google-maps-markers android-volley infowindow android-maps

这是我的地图活动

   @Override
    public void onMapReady(GoogleMap googleMap) {
        mMap = googleMap;

        JsonArrayRequest arrReq = new JsonArrayRequest(AppConfig.DATA_MAPS,
                new Response.Listener<JSONArray>(){
                    LatLng location;

                    @Override
                    public void onResponse(JSONArray response) {
                        int count = response.length();
                        for(int i = 0; i < count; i++){
                            try { JSONObject jo = response.getJSONObject(i);
                                double lat = Double.parseDouble(jo.getString("lat"));
                                double lng = Double.parseDouble(jo.getString("lng"));
                                final String judul = jo.getString("judul");

                                location = new LatLng(lat,lng);
                                final MarkerOptions options = new MarkerOptions();
                                options.position(location);
                                options.icon(BitmapDescriptorFactory.fromResource(R.drawable.error_close));
//                                options.title("judul");
//                                options.snippet("lng");
//                                options.snippet(jo.getString("shop"));
                                mMap.addMarker(options);

                                mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

                                    // Use default InfoWindow frame
                                    @Override
                                    public View getInfoWindow(Marker location) {
                                        return null;
                                    }

                                    // Defines the contents of the InfoWindow
                                    @Override
                                    public View getInfoContents(Marker location) {

                                        // Getting view from the layout file info_window_layout
                                        View v = getLayoutInflater().inflate(R.layout.info_window, null);

                                        // Getting the position from the marker
                                        LatLng latLng = location.getPosition();


                                        // Getting reference to the TextView to set latitude
                                        TextView tvLat = (TextView) v.findViewById(R.id.lat);

                                        // Getting reference to the TextView to set longitude
                                        TextView tvLng = (TextView) v.findViewById(R.id.lng);

                                        // Setting the latitude
                                        tvLat.setText("Latitude:" + judul);

                                        // Setting the longitude
                                        tvLng.setText("Longitude:" + latLng.longitude);

                                        // Returning the view containing InfoWindow contents
                                        return v;

                                    }
                                });

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

                        CameraUpdate cu = CameraUpdateFactory.newLatLng(location);
                        CameraUpdate zoom=CameraUpdateFactory.zoomTo(6);
                        mMap.moveCamera(cu);
                        mMap.animateCamera(zoom);
                        mMap.getUiSettings().setZoomControlsEnabled(true);



//                        Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_LONG).show();

                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Toast.makeText(getApplicationContext(), "onErrorResponse", Toast.LENGTH_LONG).show();
                    }
                }
        );

        AppController.getInstance().addToRequestQueue(arrReq);

    }

它显示没有错误,但问题是当我点击标记时它显示json的最后标题内容,所以每个标记都有相同的标题。但是当我在默认的infowindow中使用它时,options.title(judul); 这是正常的,每个标记都有自己的标题。它是如此令人困惑,任何帮助将是欣赏

回复: here is the response

0 个答案:

没有答案
相关问题