views:

32

answers:

1

I need to use the google map directions to show the directions between two addresses.

How can i show the google map using addresses?

Also, I have the source and destination addresses (no latitude and longitude), how can I show the directions between the address using jquery?

+1  A: 

That's very easy:

var map = new GMap2(document.getElementById('map_canvas'));
var directions = new GDirections(map);

directions.load('from: London, UK to: Glasgow, UK');

Screenshot:

Using google map GDirections with address


UPDATE:

Using the v3 API is a bit more verbose, but still straightforward:

var map = new google.maps.Map(document.getElementById('map_canvas'), {
  mapTypeId: google.maps.MapTypeId.ROADMAP
});

var directionsService = new google.maps.DirectionsService();
var directionsDisplay = new google.maps.DirectionsRenderer();

directionsDisplay.setMap(map);

var request = {
  origin: 'London, UK', 
  destination: 'Glasgow, UK',
  travelMode: google.maps.DirectionsTravelMode.DRIVING
};

directionsService.route(request, function(response, status) {
  if (status == google.maps.DirectionsStatus.OK) {
    directionsDisplay.setDirections(response);
  }
});
Daniel Vassallo
which google script file i need to include?Is it available in the latest version of GMAP (Version 3)?
Prasad
Daniel Vassallo
@Prasad: I've updated my answer with a v3 API example as well. In this case, you'd need to include the `http://maps.google.com/maps/api/js?sensor=false` script.
Daniel Vassallo
Excellent Daniel. worked great.
Prasad