0

我在點擊窗口點擊時遇到問題。無法點擊infowindow安卓谷歌地圖v2

我的代碼如下:

public class GamapA extends FragmentActivity implements OnInfoWindowClickListener{ 


Marker myMarkerOne; 

Gmap gm; 

    gm = ((SupportMapFragment)(getSupportFragmentManager().findFragmentById(R.id.map))).getMap(); 
      gm.setMapType(GoogleMap.MAP_TYPE_NORMAL); 


gm.setOnInfoWindowClickListener(this); 

LatLng one = new LatLng(12.786608, 80.221916); 

    myMarkerOne = gm.addMarker(new MarkerOptions() 
      .position(one) 
      .title("Test") 
      .snippet("Testing") 
      .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN)));  

@Override 
    public void onInfoWindowClick(final Marker marker) 
{ 
     // TODO Auto-generated method stub 
     if(marker.getPosition().equals(myMarkerOne)) 
     { 

    Toast.makeText(GamapChF.this, "Hello",Toast.LENGTH_LONG) 
    .show(); 
     } 
    } 

我沒有得到敬酒消息,當窗口已經提前clicked.Thanks。

回答

0

它不會給你敬酒,因爲

marker.getPosition()給你喜歡lat/lng: (23.06831002668264,72.58109997957945)(用於檢查該打印日誌像Log.e("marker.getPosition()-->", "" + marker.getPosition());

和要傳遞這樣的:new LatLng(23.06831, 72.58110);

如你所見(23.06831002668264,72.58109997957945)(23.06831, 72.58110)都不等於。所以它永遠不會給你Toast

所以,這insted的我會sagest您使用的標題比較或按摩,如:

if (marker.getTitle().equalsIgnoreCase("Start")) { 
      Toast.makeText(showMaps.this, "You have click on start -->", 
        Toast.LENGTH_LONG).show(); 
      Log.e("marker.getPosition()-->", "" + marker.getPosition()); 
     }