Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created February 29, 2012 23:03
Show Gist options
  • Save JakubOboza/1945220 to your computer and use it in GitHub Desktop.
Save JakubOboza/1945220 to your computer and use it in GitHub Desktop.
// Google Maps Directions combinator
function googleMapsDirectionsCombinator(start, elementId){
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var start = start;
var elementId = elementId;
var elementIdWithHash = "#" + elementId;
return function(){
directionsDisplay = new google.maps.DirectionsRenderer();
var london = new google.maps.LatLng(50.850033, -0.1800523);
var myOptions = {
zoom:7,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: london
}
map = new google.maps.Map(document.getElementById(elementId), myOptions);
directionsDisplay.setMap(map);
var end = $(elementIdWithHash).data("destination");
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
}
// user combinator to create function to display directions
var googleMapsDirections = googleMapsDirectionsCombinator("34-120, Andrychow, Malopolska, Kosciuszki 14", "map");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment