3

I'm using this: http://hpneo.github.com/gmaps/examples.html

I have two inputs where I put an address and I want to trace a route between the two points. I can add two markers, but I dont know how could I draw the route.

Any idea on how to do this?

Thanks!

This is my code...

    GMaps.geocode({
      address: address_from,
      callback: function(results, status) {
        if (status == 'OK') {
          var address_from = results[0].geometry.location;
          map.addMarker({
            lat: address_from.lat(),
            lng: address_from.lng()
          });
        }
      }       
    });

    GMaps.geocode({
      address: address_to,
      callback: function(results, status) {
        if (status == 'OK') {
          var address_to = results[0].geometry.location;
          map.addMarker({
            lat: address_to.lat(),
            lng: address_to.lng()
          });
        }
      }
    });

    map.drawRoute({
      origin: [address_from.lat(), address_from.lng()],
      destination: [address_to.lat(), address_to.lng()],
      travelMode: 'driving',
      strokeColor: '#131540',
      strokeOpacity: 0.6,
      strokeWeight: 6
    });
Mano Marks
  • 8,761
  • 3
  • 27
  • 28
Santiago
  • 2,405
  • 6
  • 31
  • 43

1 Answers1

3

This example from this similar question gets directions between two markers placed on the map by clicking (uses the Google Maps API v3 directly).

Community
  • 1
  • 1
geocodezip
  • 158,664
  • 13
  • 220
  • 245