如何在谷歌地图中绘制两个纬度经度之间的路径?

时间:2016-11-19 11:00:43

标签: android google-maps

有两个地方的纬度和经度。这是我的地图活动:

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

}

我想在这两个纬度和经度之间画一条路。我怎么能这样做?

1 个答案:

答案 0 :(得分: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 );