Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.