Created
January 8, 2012 12:37
-
-
Save dominikzogg/1578219 to your computer and use it in GitHub Desktop.
Geolocation mit Mootools, Google Map
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
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=true"></script> | |
<script type="text/javascript" src="tl_files/MooGeo-yui-compressed.js"></script> | |
<script type="text/javascript"> | |
<!--//--><![CDATA[//><!-- | |
window.addEvent('domready', function() | |
{ | |
// Configuration | |
mapdiv = 'mapdiv'; | |
latdestination = 47; | |
londestination = 8; | |
// Desination Coordinates | |
var destination = new google.maps.LatLng(latdestination, londestination); | |
// Map options | |
myOptions = { | |
zoom: 16, | |
mapTypeId: google.maps.MapTypeId.ROADMAP, | |
center: destination | |
} | |
// Create map | |
var map = new google.maps.Map(document.id(mapdiv), myOptions); | |
// Marker for desination | |
new google.maps.Marker({ | |
position: destination, | |
map: map | |
}); | |
// Get user coordinates | |
new MooGeo('visitor', | |
{ | |
onComplete: function(location) | |
{ | |
// Origin | |
origin = new google.maps.LatLng( | |
location.place.centroid.latitude, | |
location.place.centroid.longitude | |
); | |
// Initialize direction services | |
directionsService = new google.maps.DirectionsService(); | |
directionsDisplay = new google.maps.DirectionsRenderer(); | |
directionsDisplay.setMap(map); | |
// Route options | |
route = { | |
origin: origin, | |
destination: destination, | |
travelMode: google.maps.DirectionsTravelMode.DRIVING | |
}; | |
// Create route | |
directionsService.route(route, function(response, status) { | |
if (status == google.maps.DirectionsStatus.OK) { | |
directionsDisplay.setDirections(response); | |
} | |
}); | |
} | |
}); | |
}); | |
//--><!]]> | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment