我正在使用面向Google Map v2的android项目。在我的程序中,我在触摸标记的信息框时从地方api检索名称,附近,纬度和经度。但是每次都检索相同的值。但是在信息框中显示了正确的结果。如何解决此错误有人请解决此问题。



            for(final Place place : nearPlaces.results){


                // Creating a marker
                MarkerOptions markerOptions = new MarkerOptions();


                // Getting latitude of the place
                double latitude = place.geometry.location.lat;
                double longitude = place.geometry.location.lng;


                // Getting name
                String NAME = place.name;

                // Getting vicinity
                String VICINITY = place.vicinity;

             //final String REFERENCE = place.reference;
                final String slat = String.valueOf(latitude);
                   final String slon = String.valueOf(longitude);

               LatLng latLng = new LatLng(latitude, longitude);

                // Setting the position for the marker
                markerOptions.position(latLng);


                // Setting the title for the marker.
                //This will be displayed on taping the marker
                markerOptions.title(NAME + " : " + VICINITY);

                markerOptions.icon(bitmapDescriptor);

                // Placing a marker on the touched position
             mGoogleMap.addMarker(markerOptions);

                mGoogleMap.setOnInfoWindowClickListener(
                          new OnInfoWindowClickListener(){
                            @Override
                            public void onInfoWindowClick(Marker arg0) {
                                // TODO Auto-generated method stub
                                arg0.hideInfoWindow();
                            alert.showpickAlertDialog2(PlacesMapActivity.this, slat, slon, place.reference,KEY_TAG);
                            }
                          }
                        );
            }
               LatLng mylatLng = new LatLng(mylatitude, mylongitude);

             // Creating CameraUpdate object for position
                CameraUpdate updatePosition = CameraUpdateFactory.newLatLng(mylatLng);

                // Creating CameraUpdate object for zoom
                CameraUpdate updateZoom = CameraUpdateFactory.zoomBy(10);

                // Updating the camera position to the user input latitude and longitude
                mGoogleMap.moveCamera(updatePosition);

                // Applying zoom to the marker position
                mGoogleMap.animateCamera(updateZoom);

最佳答案

您在做什么错是在循环中设置OnInfoWindowClickListener

将代码带到外面,并使用slatslon检索Marker arg0getPosition

10-08 13:57
查看更多