Skip to content


Subversion checkout URL

You can clone with
Download ZIP
tree: 8ffb064ed6
Fetching contributors…

Cannot retrieve contributors at this time

47 lines (45 sloc) 2.042 kb
<!DOCTYPE html>
<title>Directions Example</title>
<script type="text/javascript" src=""></script>
<script type="text/javascript">
//Ask for HTML5 geolocation, use Modernizr to detect if we can even do it. If allow, go to show_map, if deny go to handle_error. Please note the High Accuracy flag, which may cause the location fix to take longer, but it gives a more precise reading
function get_location() {
if (Modernizr.geolocation) {
navigator.geolocation.getCurrentPosition(show_map, handle_error, {maximumAge: 75000, enableHighAccuracy: true});
console.log('We have location support!');
} else {
console.error('No HTML5 Geolocation support! Unable to divine current location!');
//Handle denied
function handle_error(err) {
if (err.code == 1) {
console.error('HTML5 Geolocation Error: Permission denied (code 1)');
if (err.code == 0) {
console.error('HTML5 Geolocation Error: Unknown error (code 0)');
if (err.code == 2) {
console.error('HTML5 Geolocation Error: Position unavailable. Network is down or positioning satellites can\'t be contacted! (code 2)');
if (err.code == 3) {
console.error('HTML5 Geolocation Error: Timed out (code 3)');
var my_address = "1600 Pennsylvania Ave NW, Washington, DC 20500";
window.location = ''+encodeURIComponent(my_address);
function show_map(position) {
console.log('Sending to Google Maps');
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
var my_address = "1600 Pennsylvania Ave NW, Washington, DC 20500";
window.location = ''+latitude+', '+longitude+'&daddr='+encodeURIComponent(my_address);
<a href="#" onClick="get_location();">Get directions to my house!</a>
Jump to Line
Something went wrong with that request. Please try again.