2016-09-27 90 views
2

我正在使用google API,並且我爲標記創建了自定義infowindow。 我需要顯示工具欄地圖,但使用這種方法 map.getUiSettings()。 setMapToolbarEnabled(true), 當我點擊標記時,它顯示我的infowindow而不是工具欄。android map.getUiSettings()。setMapToolbarEnabled(true),爲什麼不顯示工具欄?

enter image description here

CODE:

@覆蓋 公共無效onMapReady(GoogleMap的GoogleMap的){

mMap = googleMap; 
    mMap.getUiSettings().setMapToolbarEnabled(true); 
    mMap.setOnMarkerClickListener(this); 
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() { 
     @Override 
     public void onInfoWindowClick(Marker marker) { 


      MarkerCouple idtype = (MarkerCouple) marker.getTag(); 

      if (idtype.getType() == ResourceType.EVENTS && currentEvents.get(idtype.getID()) != null) { 

       Resources resources = currentResources.get(currentEvents.get(idtype.getID()).getRes_ID()); 
       Events event = currentEvents.get(idtype.getID()); 

       Intent i = new Intent(MainActivity.this, ShowEventActivity.class); 
       i.putExtra(Variable.USER_JSON, user.toJSON()); 
       i.putExtra(Variable.EVENT_JSON, event.toJSON()); 
       i.putExtra(Variable.RESOURCE_JSON, resources.toJSON()); 

       startActivityForResult(i, Variable.SHOW_EVENT); 
      } 

      if (idtype.getType() == ResourceType.PLACES && currentPlaces.get(idtype.getID()) != null) { 
       Resources resources = currentResources.get(currentPlaces.get(idtype.getID()).getRes_ID()); 
       Places place = currentPlaces.get(idtype.getID()); 

       Intent i = new Intent(MainActivity.this, ShowPlaceActivity.class); 
       i.putExtra(Variable.USER_JSON, user.toJSON()); 
       i.putExtra(Variable.PLACE_JSON, place.toJSON()); 
       i.putExtra(Variable.RESOURCE_JSON, resources.toJSON()); 

       startActivityForResult(i, Variable.SHOW_PLACE); 

      } 
     } 
    }); 

    mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() { 
     @Override 
     public View getInfoWindow(Marker marker) { 

      View v = getLayoutInflater().inflate(R.layout.marker_preview, null); 
      ImageView m = (ImageView) v.findViewById(R.id.marker_image); 
      m.setImageBitmap(Bitmap.createScaledBitmap(imageToShow, 600, 400, true)); 
      return v; 
     } 

     @Override 
     public View getInfoContents(Marker marker) { 


      return null; 
     } 
    }); 
    new MarkerAsync().execute(); 


} 

@Override 
public boolean onMarkerClick(final Marker marker) { 

    MarkerCouple idtype = (MarkerCouple) marker.getTag(); 


    if (idtype.getType() == ResourceType.EVENTS && currentEvents.get(idtype.getID()) != null) { 
     Events event = currentEvents.get(idtype.getID()); 
     final Resources resources = currentResources.get(event.getRes_ID()); 
     Picasso.with(MainActivity.this).invalidate(Variable.DOWNLOAD_URL + resources.getURI()); 
     new AsyncTask<Void, Void, Void>() { 
      @Override 
      protected Void doInBackground(Void... params) { 
       try { 
        imageToShow = Picasso.with(MainActivity.this).load(Variable.DOWNLOAD_URL + resources.getURI()).get(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       return null; 
      } 

      @Override 
      protected void onPostExecute(Void v) { 
       marker.showInfoWindow(); 

      } 
     }.execute(); 


    } 


    if (idtype.getType() == ResourceType.PLACES && currentPlaces.get(idtype.getID()) != null) { 

     Places place = currentPlaces.get(idtype.getID()); 
     final Resources resources = currentResources.get(place.getRes_ID()); 
     Picasso.with(MainActivity.this).invalidate(Variable.DOWNLOAD_URL + resources.getURI()); 
     Picasso.with(MainActivity.this).invalidate(Variable.DOWNLOAD_URL + resources.getURI()); 
     new AsyncTask<Void, Void, Void>() { 
      @Override 
      protected Void doInBackground(Void... params) { 
       try { 
        imageToShow = Picasso.with(MainActivity.this).load(Variable.DOWNLOAD_URL + resources.getURI()).get(); 
       } catch (IOException e) { 
        e.printStackTrace(); 
       } 
       return null; 
      } 

      @Override 
      protected void onPostExecute(Void v) { 
       marker.showInfoWindow(); 

      } 
     }.execute(); 

    } 


    return true; 
} 
+0

請發表您的代碼 –

+0

我貼我的代碼 – helloimluca

回答

1

只需return false;onMarkerClick()

the documentation

公共抽象布爾onMarkerClick(標記標記)

返回

真,如果聽衆已經消耗的事件(即,不應該發生的默認行爲),否則爲false(即默認行爲應該發生)。默認行爲是讓相機移動到標記並出現一個信息窗口。

+0

如果我返回false,我拋出異常 – helloimluca

+0

什麼是例外? – antonio

+0

java.lang.NullPointerException:試圖在null對象引用 上調用虛擬方法'int android.graphics.Bitmap.getWidth()',位於android.graphics.Bitmap.createScaledBitmap(Bitmap.java:591) at tesi.myview .MainActivity $ 3.getInfoWindow(MainActivity.java:274) – helloimluca

相關問題