Created
July 22, 2011 02:05
-
-
Save Veejay/1098737 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function initialize(){ | |
with(google.maps){ | |
// Let's query the geocoding service to set the bounds for the map | |
var myOptions = { | |
zoom: 8, | |
mapTypeId: MapTypeId.ROADMAP | |
}; | |
// The actual map | |
var map = new Map(document.getElementById("map_canvas"), myOptions); | |
var geocoder = new Geocoder(); | |
var origin, destination; | |
geocoder.geocode({'address': 'Watertown, MA 02472', 'region':'us'}, function(result, status){ | |
origin = result[0].geometry.location; | |
geocoder.geocode({'address': 'Belmont, MA 02478', 'region':'us'}, function(result, status){ | |
destination = result[0].geometry.location; | |
// SHIT IS RIDIC :/ | |
var south_west = new LatLng(Math.min(origin.lat(), destination.lat()), Math.min(origin.lng(), destination.lng())); | |
var north_east = new LatLng(Math.max(origin.lat(), destination.lat()), Math.max(origin.lng(), destination.lng())); | |
var bounds = new LatLngBounds(south_west, north_east); | |
map.fitBounds(bounds); | |
}); | |
}); | |
// Renderer used for the overlays | |
var renderer = new DirectionsRenderer({'preserveViewport':true}); | |
// Google Maps Directions Service provides the information | |
// about directions and so forth | |
var service = new DirectionsService(); | |
// Let's create a DirectionsRequest object to send to the DirectionsService | |
var request = { | |
'origin' : 'Watertown, MA 02472', // FIXME: Seems overkill and not generic | |
'destination' : 'Belmont, MA 02478', // FIXME: Seems overkill and not generic | |
'travelMode' : TravelMode.DRIVING, | |
'region' : 'us' | |
}; | |
// Let's query the Google Maps Directions Service and process the result | |
service.route(request, function(result, status){ | |
// For information about the status parameter of the callback | |
// See http://goo.gl/2vg6H | |
console.log(status); | |
renderer.setDirections(result); | |
renderer.setMap(map); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment