-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
157 lines (130 loc) · 3.8 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset=utf-8>
<meta name="viewport" content="width=620">
<title>Geo Location Demo</title>
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/geo.css">
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/yqlgeo.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script>
$(window).ready(function(){
initiate_watchlocation();
});
var watchProcess = null;
var map;
var mapmarker;
function initiate_watchlocation(){
if(watchProcess == null){
map = mapCanvas();
if(navigator.geolocation)
watchProcess = navigator.geolocation.watchPosition(handle_geolocation_query, handle_errors)
else
yqlgeo.get('visitor', normalize_yql_response);
}
}
function stop_watchlocation(){
if(watchProcess != null){
navigator.geolocation.clearWatch(watchProcess);
watchProcess = null;
}
}
function handle_errors(error){
switch(error.code){
case error.PERMISSION_DENIED:
alert("user did not share geolocation");
break;
case error.POSITION_UNAVAILABLE:
alert("could not detect current position");
break;
case error.TIMEOUT:
alert("retrieving position timed out ");
break;
default:
alert("unknown error");
break;
}
}
/*function initiate_geolocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors);
} else{
yqlgeo.get('visitor', normalize_yql_response);
}
}*/
function normalize_yql_resposne(response){
if(response.error){
var error = { code:0}
handle_error(error);
return;
}
var position = {
coords : {
latitude: response.place.centroid.latitude,
longitude: response.place.centroid.longitude
},
address : {
city: response.place.locality2.content,
region: response.place.admin1.content,
country: response.place.country.content
}
};
handle_geolocation_query(position)
}
function mapCanvas(){
var mapcanvas = $("<div id='mapcanvas' class='mapClass'></div>");
var latlng = new google.maps.LatLng(48.4228527, -123.36852160000001);
var image = new google.maps.MarkerImage(
'./images/bluedot.png',
null,
null,
new google.maps.Point( 8, 8 ),
new google.maps.Size( 17, 17 )
);
$("article").append(mapcanvas);
var myOptions = {
zoom: 15,
center: latlng,
mapTypeControl: false,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(mapcanvas[0], myOptions);
mapmarker = new google.maps.Marker({
flat: true,
icon: image,
position: latlng,
map: map,
optimized: false,
title: "You are here",
visible: true
});
return map;
}
function handle_geolocation_query(position){
var text = "Latitude: " + position.coords.latitude + "<br/>" +
"Longitude " + position.coords.longitude + "<br/>" +
"Accuracy: " + position.coords.accuracy + "m<br/>" +
"Time: " + new Date(position.timestamp);
$("#status").html(text).addClass('success');
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
mapmarker.setPosition(latlng);
map.panTo(latlng);
}
</script>
</head>
<body>
<section id="wrapper">
<header>
<h1>Geo Location Demo</h1>
</header>
<meta name="viewport" content="width=620"/>
<article id="mapArticle">
<p>Finding your location: <span id="status">checking...</span></p>
</article>
</section>
<body>
</html>