Gmaps4rails - Directions


SUBMITTED BY: jlolk3r

DATE: Jan. 20, 2016, 3:08 a.m.

FORMAT: JavaScript

SIZE: 787 Bytes

HITS: 1471

  1. var directionsDisplay = new google.maps.DirectionsRenderer();
  2. var directionsService = new google.maps.DirectionsService();
  3. function calcRoute() {
  4. var origin = new google.maps.LatLng(41.850033, -87.6500523);
  5. var destination = new google.maps.LatLng(42.850033, -85.6500523);
  6. var request = {
  7. origin: origin,
  8. destination: destination,
  9. travelMode: google.maps.TravelMode.DRIVING
  10. };
  11. directionsService.route(request, function(response, status) {
  12. if (status == google.maps.DirectionsStatus.OK) {
  13. directionsDisplay.setDirections(response);
  14. }
  15. });
  16. }
  17. calcRoute();
  18. var handler = Gmaps.build('Google');
  19. handler.buildMap({ internal: {id: 'directions'}}, function(){
  20. directionsDisplay.setMap(handler.getMap());
  21. });

comments powered by Disqus