Skip to content

Instantly share code, notes, and snippets.

@dominikzogg
Created January 8, 2012 12:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dominikzogg/1578219 to your computer and use it in GitHub Desktop.
Save dominikzogg/1578219 to your computer and use it in GitHub Desktop.
Geolocation mit Mootools, Google Map
<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