不想在infowindow中显示引用

时间:2013-06-28 06:57:15

标签: android google-places-api google-maps-api-2 infowindow

我试图从谷歌地方获取一些地方列表并在googlemap api v2中显示。此外,我想显示infowindow,但在这里我只能通过信息窗口参数访问地方参考。问题是infowindow也会显示参考。这是一件令人讨厌的事情。我不想在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());  
                                    }
                                  }
                                );

1 个答案:

答案 0 :(得分:1)

保持Map<Marker, Place>&amp;不要将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);  
                                }
                              }
                            );