Android 如何在谷歌地图中绘制两个经纬度之间的路径?
有两个地方的纬度和经度是给定的。这是我的地图活动:Android 如何在谷歌地图中绘制两个经纬度之间的路径?,android,google-maps,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 t
@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));
}
我想在这两个纬度和经度之间画一条路径。我怎么做呢?您必须添加
多段线选项
并添加新的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 );
你们在github上试过这个例子吗?但我不需要多段线,我需要路径