2015-04-29 22 views
0

我的Google地圖在我的應用中顯示完整。但問題是如何在我的應用程序中添加多個地圖標記。爲不同的地點?而我嘗試一些從這裏編碼,以我的問題,但不會工作。如何在Android應用中添加多個地圖標記

這樣

import android.os.Bundle; 
import android.support.v4.app.FragmentActivity; 

import com.google.android.gms.maps.GoogleMap; 
import com.google.android.gms.maps.SupportMapFragment; 
import com.google.android.gms.maps.model.LatLng; 
import com.google.android.gms.maps.model.MarkerOptions; 

public class MapsActivity extends FragmentActivity { 




    private GoogleMap mMap; // Might be null if Google Play services APK is not available. 

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

    } 


    @Override 
    protected void onResume() { 
     super.onResume(); 
     setUpMapIfNeeded(); 
    } 

    private void setUpMapIfNeeded() { 

     if (mMap == null) { 
      // Try to obtain the map from the SupportMapFragment. 
      mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)) 
        .getMap(); 
      // Check if we were successful in obtaining the map. 
      if (mMap != null) { 
       setUpMap(); 
      } 
     } 
    } 


    private void setUpMap() { 

    } 
} 

回答

0

您可以撥打

LatLng latLng = new LatLng(double_lat, double_long); 
mMap.addMarker(new MarkerOptions().position(latLng)); 

你要多少次

+0

我不沒有,但多次可能 –

0

如果您想要在地圖上添加並顯示標記,請按照以下步驟進行:步驟1:創建一個ARRAYList(MarkerOptions)MarkerList
2 - 創建一個將標記添加到MarkerList的函數
3-創建一個將MarkerList中的所有標記添加到地圖的函數。

創建MarkerList後,這是addMarkerToList()

public void AddMarkerToList(double latitude,double longitude , String Name) 
{ 
    //Add Marker using Object 
    //we put just latitude and longitude and tilte of the marker 
    MarkerList.add(new MarkerOptions().position(new LatLng(latitude,longitude)).title(Name)); 

這到底是最後的功能:

public void showMarker() 
{ 
for (int i=0 ;i<MarkerList.size();i++) { 
mMap.addMarker(MarkerList.get(i)); 
} 
} 
相關問題