Created
February 29, 2012 23:03
-
-
Save JakubOboza/1945220 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// 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