2013-06-28 19 views
0

我試圖從google地方獲取一些地點列表並在googlemap api v2中顯示它。另外我想展示infowindow,但是在這裏我只能通過信息窗口參數獲取地點引用。問題是infowindow也會顯示參考。這是一件討厭的事情。我不想在infowindow裏面顯示它,但是我想在這個infowindow clicklistener中傳遞給該方法的引用,我該怎麼做?任何幫助表示讚賞...不想在infowindow中顯示引用

代碼

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

保持一個Map<Marker, Place> &不要把參考到代碼段。

當點擊信息窗口,查找標記在地圖上,並獲得相應的地方

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); 
           } 
           } 
          ); 
+0

如果你給更多的解釋或一個例子是更好 –

+0

答案的第一部分仍然給出了同樣的效果,我在question.And提到的我不明白答案的第二部分是絕對錯誤因爲我們無法訪問參考v在這種情況下,在信息窗口點擊監聽器內部是可變的。 –