codepath / codepath/android_guides

Drawing Map Directions

Open
#141 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
No language data
Stars
28.3k
Forks
6.2k
PR merge metrics
No merged PRs in 30d

Description

Add a section to our [maps guide](http://guides.codepath.com/android/Google-Maps-API-v2-Usage) on drawing driving directions:
- [Android Maps Directions](https://github.com/akexorcist/Android-GoogleDirectionLibrary)
- [Step-by-Step Tutorial](http://www.akexorcist.com/2015/12/google-direction-library-for-android-en.html)

``` java
public void drawDirections(GoogleMap map, fromLatLng, toLatLng) {
GoogleDirection.withServerKey("YOUR_SERVER_API_KEY")
.from(new LatLng(37.7681994, -122.444538))
.to(new LatLng(37.7749003,-122.4034934))
.avoid(AvoidType.FERRIES)
.avoid(AvoidType.HIGHWAYS)
.execute(new DirectionCallback() {
@Override
public void onDirectionSuccess(Direction direction) {
if(direction.isOK()) {
onDirectionSuccess(direction);
} else {
// Error case
}
}

@Override
public void onDirectionFailure(Throwable t) {
// Error case
}
});
}

@Override
public void onDirectionSuccess(Direction direction) {
// Draw markers
googleMap.addMarker(new MarkerOptions().position(origin));
googleMap.addMarker(new MarkerOptions().position(destination));
// Draw lines
ArrayList directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint();
googleMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 5, Color.RED));
}
```

Other:
- [MapBox Directions](https://github.com/mapbox/mapbox-directions-android)
- [Manual Guide](http://blog-emildesign.rhcloud.com/?p=822)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.