2016-03-05 93 views
-2

我試圖在谷歌搜索,但我coulnt找到確切的解決方案。我如何從地圖上的標記開始另一項活動?我想點擊標記並移動到另一個活動。如何從Google map api上的標記開始活動?

這裏是我的代碼,

public class MapsActivity extends FragmentActivity implements OnMapReadyCallback, GoogleMap.OnMapLongClickListener { 


    private GoogleMap mMap; 


    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_maps); 

     // 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); 

    } 
    /** 
    * Manipulates the map once available. 
    * This callback is triggered when the map is ready to be used. 
    * This is where we can add markers or lines, add listeners or move the camera. In this case, 
    * we just add a marker near Sydney, Australia. 
    * If Google Play services is not installed on the device, the user will be prompted to install 
    * it inside the SupportMapFragment. This method will only be triggered once the user has 
    * installed Google Play services and returned to the app. 
    */ 

    @Override 
    public void onMapReady(GoogleMap googleMap) { 
     mMap = googleMap; 
     mMap.setOnMapLongClickListener(this); 

    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.hava_durumu, menu); 
     return true; 
    } 
    @Override 
    public void onMapLongClick(LatLng point) { 
     mMap.addMarker(new MarkerOptions() 
       .position(point) 
       .title("You are here") 
       .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED))); 
    } 
} 
+1

訪問這個http://stackoverflow.com/questions/16635530/android-google-map-clicked-marker-opened-new-activity-or-greater-window –

回答

0

可以使用setOnMarkerClickListener方法得到標記

的點擊

試試這個:

mMap.setOnMarkerClickListener(new OnMarkerClickListener() 
       { 

        @Override 
        public boolean onMarkerClick(Marker arg0) { 

          //code for startactivity 
         return true; 
        } 

       });  
+0

感謝您的回答。而不是OnMapLongClick方法?或我應該在哪裏使用它? –

+0

它工作感謝Aakash –

相關問題