-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
97 lines (88 loc) · 2.11 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<!DOCTYPE:html>
<html>
<head>
<title>Geolocation Example</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
</head>
<body>
<div id="map"></div>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
detectBrowser();
initGoogleMap();
getLocation();
// Detect support and request the current location.
function getLocation()
{
if ( navigator.geolocation )
{
navigator.geolocation.getCurrentPosition(handlePosition, handleError);
}
else
{
alert("Sorry, geolocation is not supported.");
}
}
// Receives a successful geolocation response.
function handlePosition(pos)
{
// Center the map on the current location
latlng = new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude);
map.setCenter(latlng);
// Drop a marker on the current location
marker = new google.maps.Marker
({
map: map,
draggable: false,
animation: google.maps.Animation.DROP,
position: latlng
});
}
// Receives and display geolocation request error.
function handleError(error)
{
switch (error.code)
{
case error.PERMISSION_DENIED:
alert('Permission was denied');
break;
case error.POSITION_UNAVAILABLE:
alert('Position is currently unavailable.');
break;
case error.PERMISSION_DENIED_TIMEOUT:
alert('User took to long to grant/deny permission.');
break;
case error.UNKNOWN_ERROR:
alert('An unknown error occurred.')
break;
}
}
// Initialize and display the google map in the element with id "map"
function initGoogleMap()
{
options =
{
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map"), options);
}
// Detect the current browser and display full screen for Android / iPhone
function detectBrowser()
{
var userAgent = navigator.userAgent;
var mapDiv = document.getElementById("map");
if (userAgent.indexOf('iPhone') != -1 || userAgent.indexOf('Android') != -1 )
{
mapDiv.style.width = '100%';
mapDiv.style.height = '100%';
}
else
{
mapDiv.style.width = '600px';
mapDiv.style.height = '800px';
}
}
</script>
</body>
</html>