2017-10-06 56 views
-9

嗨,大家好,我點擊Google地圖標記發起新活動時遇到問題,當我點擊它時,沒有窗口彈出。點擊谷歌地圖後,標記新的活動並不開始

這裏是整個代碼我使用:

public class MainActivity extends FragmentActivity implements OnMapReadyCallback { 

private GoogleMap mMap; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    // Obtain the SupportMapFragment and get notified when the map is ready to be used. 
    SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() 
      .findFragmentById(R.id.map); 
    mapFragment.getMapAsync(this); 
@Override 
public void onMapReady(final GoogleMap googleMap) { 
    mMap = googleMap; 

    // Add a marker in Sydney and move the camera 
    LatLng sydney = new LatLng(-34, 151); 
    mMap.addMarker(new MarkerOptions().position(sydney)); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney)); 
    mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { 
     @Override 
     public boolean onMarkerClick(Marker marker) { 
      if (marker.equals(mMap)){ 
       Intent intent = new Intent(MainActivity.this, MarkerAdded.class); 
       startActivity(intent); 
      } 
       return false; 
     } 
    }); 
} 
+7

您要比較'和'Marker' GoogleMap'對象,他們將是顯然不等於 – Selvin

+0

什麼你的意思是說這個嗎? –

+0

marker.equals(mMap) 查看您的狀態 – Namy

回答

0
mMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() { 
      @Override 
      public void onInfoWindowClick(Marker marker) { 
      Intent intent = new Intent(MainActivity.this, MarkerAdded.class); 
      startActivity(intent); 


      } 
     }); 

mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { 
      @Override 
      public boolean onMarkerClick(Marker marker) { 
       if (marker.equals(yourMarkerObj))// you should compare with your marker not with the google map obj or you can normally pass the intent without condition 
{ 
        Intent intent = new Intent(MainActivity.this, MarkerAdded.class); 
        startActivity(intent); 
       } 
        return false; 
      } 
    }); 
+0

現在它的工作原理,感謝和抱歉頭腦滯後。 –

+0

PLZ放棄它的投票.. – Namy

相關問題