1

我正在使用一个面向谷歌地图 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);
4

2 回答 2

1

你做错了什么设置OnInfoWindowClickListener在一个循环中。

将该代码带到外部slatslon使用Marker arg0.getPosition

于 2013-06-04T20:10:50.430 回答
0

还有其他人也在为这个问题而苦苦挣扎。

您假设 slat 和 slong 值将传递到 onInfoWindowClick() 方法,但您总是在那里获得相同的值。

这是其他一些人就这个话题进行的讨论。

于 2013-06-04T05:39:46.310 回答