Where will you go from here? – Directions in the Google Maps API Version 3

Where will you go from here? - Directions in the Google Maps API Version 3Google continues to expand its third version of the maps API to include features already in the second version. Most recently, they’ve added driving directions, which gives programmatic access to the routing data between two points. As with the rest of Maps V3, which was released in May, the team took a fresh approach, so some interfaces have changed.

Somehow they’ve managed to fit in more features when the apparent motto of V3 has been less. To get a feel for the code, view the source of the new directions examples or check out the directions section of the reference guide.

Example code:

var map = new google.maps.Map(document.getElementById("map_canvas"), {
  zoom: 7,
  mapTypeId: google.maps.MapTypeId.ROADMAP,
  center: new google.maps.LatLng(-33.868011, 151207566)
});

var directionsRenderer = new google.maps.DirectionsRenderer();
directionsRenderer.setMap(map);
directionsRenderer.setPanel(document.getElementById('directionsPanel'));

var directionsService = new google.maps.DirectionsService();
var request = {
  origin: "Sydney, NSW",
  destination: "Chatswood, NSW",
  travelMode: google.maps.DirectionsTravelMode.DRIVING,
  unitSystem: google.maps.DirectionsUnitSystem.METRIC,
  provideTripAlternatives: true
};
directionsService.route(request, function(response, status) {
  if (status == google.maps.DirectionsStatus.OK) {
    directionsRenderer.setDirections(response);
  } else {
    alert('Error: ' + status);
  }
});

Link: googlegeodevelopers.blogspot.com

Tags: ,

Added by Daniel on Monday, November 23rd, 2009 | Filed under Tech Tips

Leave a Reply