-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap.html
77 lines (70 loc) · 1.97 KB
/
map.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
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width">
<script src="js/jquery-1.4.2.min.js"></script>
<script src="js/yqlgeo.js"></script>
<script>
function initiate_geolocation() {
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_error);
}
else
{
yqlgeo.get('visitor', normalize_yql_response);
}
}
function handle_error(error){
switch(error.code)
{
case error.PERMISSION_DENIED: alert("user did not share Geolocation data");
break;
case error.POSITION_UNAVAILABLE: alert("could not detect current position");
break;
case error.TIMEOUT: alert("retrieving position timedout");
break;
default: alert("unknown error");
break;
}
}
function normalize_yql_response(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 handle_geolocation_query(position){
var image_url = "http://maps.google.com/maps/api/staticmap?sensor=false¢er=" + position.coords.latitude + ',' + position.coords.longitude +
"&zoom=14&size=300x400&markers=color:blue|label:S|" + position.coords.latitude + ',' + position.coords.longitude;
jQuery("#map").remove();
jQuery(document.body).append(
jQuery(document.createElement("img")).attr("src", image_url).attr('id','map')
);
}
jQuery(window).ready(function(){
jQuery("#btnInit").click(initiate_geolocation);
})
</script>
</head>
<body>
<div>
<button id="btnInit" >Find my location</button>
</div>
</body>
</html>