2017-08-12 117 views
2

我目前在我的android应用中使用用户位置标记在开放式地图上绘制谷歌地图,当用户点击地图中的某个位置时,蓝色标记将显示用户位置之间的折线(目标标记)标记和目的地标记这样的图像:在道路上绘制折线android

example image

How can i draw this lines in roads ???
我已经以下代码:

@Override 
public void onMapReady(final GoogleMap googleMap) { 
    this.googleMap = googleMap; 
    googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() { 
     @Override 
     public void onMapLongClick(LatLng latLng) { 
      destinationLocation = new Location(LocationManager.GPS_PROVIDER); 
      destinationLocation.setLatitude(latLng.latitude); 
      destinationLocation.setLongitude(latLng.longitude); 
      destinationMarker = googleMap.addMarker(new MarkerOptions().position(latLng).title("your destination").icon(BitmapDescriptorFactory.fromResource(R.drawable.ic_destination_marker))); 
      Polyline line = googleMap.addPolyline(new PolylineOptions() 
        .add(new LatLng(userLocation.getLatitude(), 
          userLocation.getLongitude()), new LatLng(destinationLocation.getLatitude(), 
          destinationLocation.getLongitude())).color(Color.BLUE).width(10)); 
     } 
    }); 
} 

回答