This repository has been archived by the owner on Jun 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
directions1.html
47 lines (45 loc) · 1.99 KB
/
directions1.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
<head>
<title>Directions Example</title>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.0.6/modernizr.min.js"></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 = 'http://maps.google.com/maps?daddr='+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 = 'http://maps.google.com/maps?saddr='+latitude+', '+longitude+'&daddr='+encodeURIComponent(my_address);
}
</script>
</head>
<body>
<a href="#" onClick="get_location();">Get directions to my house!</a>
</body>
</html>