-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathgeolocation.html
58 lines (45 loc) · 1.5 KB
/
geolocation.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
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
<link rel="stylesheet" href="w3.css">
<head>
<meta name=viewport content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Geolocation microdemo</title>
</head>
<body>
<div class="w3-container w3-orange">
Get geolocation and paint on a map.
(Knock off of Mozilla's https://jsfiddle.net/4zpx2vks)
</div>
</body>
<script>
var loc = window.location.href+'';
if (loc.indexOf('http://')==0){
window.location.href = loc.replace('http://','https://');
}
</script>
<script>
function geoFindMe() {
var output = document.getElementById("out");
if (!navigator.geolocation){
output.innerHTML = "<p>Geolocation is not supported by your browser</p>";
return;
}
function success(position) {
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
output.innerHTML = '<p>Latitude is ' + latitude + 'deg <br>Longitude is ' + longitude + 'deg</p>';
var img = new Image();
img.src = "https://maps.googleapis.com/maps/api/staticmap?center=" + latitude + "," + longitude + "&zoom=13&size=300x300&sensor=false";
output.appendChild(img);
};
function error() {
output.innerHTML = "Unable to retrieve your location";
};
output.innerHTML = "<p>Locating...</p>";
navigator.geolocation.getCurrentPosition(success, error);
}
</script>
<p><button onclick="geoFindMe()" class="w3-btn-primary w3-teal w3-round">Show my location</button></p>
<div id="out"></div>
</html>