android - Google places 在所有执行中检索相同的值

标签 android google-places-api android-maps-v2

我正在使用一个面向 Google map v2 的 android 项目。在我的程序中,我在触摸标记的信息框时从 places 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

将该代码取出并使用 getPositionMarker arg0 中检索 slatslon

关于android - Google places 在所有执行中检索相同的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16909722/

相关文章:

google-maps - 如何通过Google Places API获取业务 "description"?

google-maps - Google Place Autocomplete API 显示无效地址

android - MapsV2 如何伪造点击 myLocation 按钮

android - 从数据库填充 ListView

java - 单击按钮停止动画

Android - USB 开放附件模式错误

java - 在android中通过蓝牙发送文件时出错?

android - 如何使用 google places 在 android 中获取一个城市中的所有百货商店?

android-maps-v2 - map v2 我的位置图层样式

javascript - 如何正确地为在 Android Studio 中创建的 map 设置动画以跟随标记