Skip to content

Instantly share code, notes, and snippets.

@hanigamal
Forked from omkz/snaptoroad.js
Last active February 25, 2019 14:54
Show Gist options
  • Save hanigamal/44a259e1fb5e18caf3ee to your computer and use it in GitHub Desktop.
Save hanigamal/44a259e1fb5e18caf3ee to your computer and use it in GitHub Desktop.
google maps API javascript v3 - polyline snap to road
var directionsService = new google.maps.DirectionsService();
directionsService.route(request, function (response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var polyline = new google.maps.Polyline(polylineOptions);
var path = response.routes[0].overview_path;
for (var x in path) {
polyline.getPath().push(path[x]);
}
polyline.setMap(map);
polylines.push(polyline);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment