0

我试图从谷歌地方获取一些地方列表并将其显示在 googlemap api v2 中。我也想显示信息窗口,但在这里我只能通过信息窗口参数访问位置参考。问题是信息窗口也会显示参考。这是一件讨厌的事情。我不想在 infowindow 中显示它,但我希望在这个 infowindow clicklistener 中引用以传递给方法我该怎么做?任何帮助表示赞赏...

代码

 for(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;
                        //Reference of a place
                        String REFERENCE = place.reference;
                       LatLng latLng = new LatLng(latitude, longitude);
                        // Setting the position for the marker
                        markerOptions.position(latLng);
                        // Setting the title for the marker. 
                        markerOptions.title(NAME + " : " + VICINITY);                   
                        markerOptions.snippet(REFERENCE);
                        markerOptions.icon(bitmapDescriptor);

                        // Placing a marker on the touched position
                     final Marker marker = mGoogleMap.addMarker(markerOptions); 
                        mGoogleMap.setOnInfoWindowClickListener(
                                  new OnInfoWindowClickListener(){
                                    @Override
                                    public void onInfoWindowClick(Marker arg0) {
                                        // TODO Auto-generated method stub
                                        arg0.hideInfoWindow();
                                        double dlat=arg0.getPosition().latitude;
                                        double dlon=arg0.getPosition().longitude;
                                    alert.showpickAlertDialog2(PlacesMapActivity.this,dlat , dlon, arg0.getSnippet());  
                                    }
                                  }
                                );
4

1 回答 1

1

保留一个Map<Marker, Place>& 不要将 REFERENCE 放入片段中。

单击信息窗口时,在地图中查找标记并获取相应的地点

HashMap<Marker, Place> markerPlaces = new HashMap<Marker, Place>();
for(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;
                    //Reference of a place
                    String REFERENCE = place.reference;
                   LatLng latLng = new LatLng(latitude, longitude);
                    // Setting the position for the marker
                    markerOptions.position(latLng);
                    // Setting the title for the marker. 
                    markerOptions.title(NAME + " : " + VICINITY);                   
                    markerOptions.icon(bitmapDescriptor);

                    // Placing a marker on the touched position
                 final Marker marker = mGoogleMap.addMarker(markerOptions); 
                    markerPlaces.put(marker, place);
                    mGoogleMap.setOnInfoWindowClickListener(
                              new OnInfoWindowClickListener(){
                                @Override
                                public void onInfoWindowClick(Marker arg0) {
                                    // TODO Auto-generated method stub
                                    arg0.hideInfoWindow();
                                    double dlat=arg0.getPosition().latitude;
                                    double dlon=arg0.getPosition().longitude;
                                    Place p = markerPlaces.get(marker);
                                alert.showpickAlertDialog2(PlacesMapActivity.this,dlat , dlon, p.reference);  
                                }
                              }
                            );

或者,在这种情况下,您可以在 onInfoWindowClick 中放置和使用它的最终引用:

for(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;
                    //Reference of a place
                    String REFERENCE = place.reference;
                   LatLng latLng = new LatLng(latitude, longitude);
                    // Setting the position for the marker
                    markerOptions.position(latLng);
                    // Setting the title for the marker. 
                    markerOptions.title(NAME + " : " + VICINITY);                   
                    markerOptions.icon(bitmapDescriptor);

                    // Placing a marker on the touched position
                 final Marker marker = mGoogleMap.addMarker(markerOptions);
                 final Place p = place;
                    markerPlaces.put(marker, place);
                    mGoogleMap.setOnInfoWindowClickListener(
                              new OnInfoWindowClickListener(){
                                @Override
                                public void onInfoWindowClick(Marker arg0) {
                                    // TODO Auto-generated method stub
                                    arg0.hideInfoWindow();
                                    double dlat=arg0.getPosition().latitude;
                                    double dlon=arg0.getPosition().longitude;
                                alert.showpickAlertDialog2(PlacesMapActivity.this,dlat , dlon, p.reference);  
                                }
                              }
                            );
于 2013-06-28T07:18:53.620 回答