emen emen -3 years ago 141
Android Question

draw polyline on roads in android

I currently have a google map in my android app with user location marker on open map and when user click to a position in map a blue marker will shows(destination marker) with a polyline between user location marker and destination marker like this image:

example image

How can i draw this lines in roads ???

I have following code :

public void onMapReady(final GoogleMap googleMap) {
this.googleMap = googleMap;
googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {
public void onMapLongClick(LatLng latLng) {
destinationLocation = new Location(LocationManager.GPS_PROVIDER);
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(),

Answer Source

use this tutorial and add your location to this tutorial code like your codes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download