2015-10-25 39 views

回答

0

對於第一種情況,使用this。爲了讓它工作,幾乎可以自我解釋,但這裏有一個方便的例子。

gMap.setOnMapClickListener(new OnMapClickListener() { 

     @Override 
     public void onMapClick(LatLng arg0) { 
      // TODO Auto-generated method stub 
      Log.d("LatLng", arg0.latitude + "-" + arg0.longitude); 
     } 
    }); 
1

您可以通過MapFragment創建某種覆蓋,並設置onTouchListener它。

<RelativeLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <fragment 
     android:id="@+id/map" 
     class="com.google.android.gms.maps.SupportMapFragment" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 

    <View 
     android:id="@+id/mapOverlay" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"/> 
</RelativeLayout> 

Java代碼:

View mapOverlay = (View) findViewById(R.id.mapOverlay);   
mapOverlay.setOnTouchListener(new View.OnTouchListener() { 
    @Override public boolean onTouch(View v, MotionEvent event) { 
     switch (event.getAction()) { 
      case MotionEvent.ACTION_DOWN: 
       // handle tap 
       break; 
      case MotionEvent.ACTION_UP: 
       // handlerelease 
       break; 
     } 

     return false; // return false if you want propagate click to map 
    } 
}); 
+0

感謝ü...這是這麼多有用的.. – CodeCameo

+1

其實在,還有我覺得打字錯誤。它應該是: - android:id =「@ + id/mapOverlay」 – Mrigank

+0

我試過了你的代碼,但是爲什麼MotionEvent.ACTION_UP永遠不會被調用? – sThiago