2016-11-19 32 views
-1

有緯度和兩個地經度given.This是我的地圖活動:如何在谷歌地圖中繪製兩個緯度經度之間的路徑?

@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); 
} 

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

    // double array [] = {44.968046 ,-94.420307 ,44.33328,-89.132008, 33.755787,-116.359998,33.844843,-116.54911 ,44.92057 ,-93.44786}; 
    // Add a marker in Sydney and move the camera 

    double lat1 = 23.781388 ; 
    double lon1 = 90.425500 ; 
    double lat2 = 23.780270 ; 
    double lon2 = 23.780270 ; 

    LatLng place1 = new LatLng(lat1, lon1); 
    LatLng place2 = new LatLng(lat2, lon2); 

    mMap.addMarker(new MarkerOptions().position(place1).title("Marker in Pran RFL")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(place1)); 

    mMap.addMarker(new MarkerOptions().position(place2).title("Marker in Gulshan")); 
    mMap.moveCamera(CameraUpdateFactory.newLatLng(place2)); 

} 

我要畫這對夫妻的緯度之間的路徑和longitude.How我能做到嗎?

+0

你嘗試在github這個https://github.com/hiepxuan2008/GoogleMapDirectionSimple/例子? –

回答

0

您必須添加PolyLineOptions並添加新LatLng()試試這個代碼

PolylineOptions options = new PolylineOptions(); 

    options.color(Color.parseColor("#CC0000FF")); 
    options.width(5); 
    options.visible(true); 
    options.add(new LatLng(lat1 ,lon1)); 
    options.add(new LatLng(lat2 ,lon2)); 

    mMap.addPolyline(options); 
+0

但我不需要折線,我需要路徑 –

相關問題