Skip to content

Instantly share code, notes, and snippets.

@loris
Created March 21, 2013 22:08
Show Gist options
  • Save loris/5217237 to your computer and use it in GitHub Desktop.
Save loris/5217237 to your computer and use it in GitHub Desktop.
Simple HTML5 page that redirect the user to Google Maps showing directions from its location (using HTML5 geolocation) to the place set as query parameter (ie, map-direction.html?Empire+State+Building+NYC). Useful in Alfred WebSearch.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script>
var daddr = window.location.search.slice(1);
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(data){
if (data.coords) {
window.location = 'https://maps.google.fr/maps?saddr=' + data.coords.latitude + ',' + data.coords.longitude + '&daddr=' + daddr;
}
});
}
</script>
</head>
<body>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment