-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex_3.html
76 lines (69 loc) · 1.98 KB
/
index_3.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
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery-1.10.2.min.js"></script>
<script src="js/yqlgeo.js"></script>
<script>
$(window).ready(function(){
$("#btnInit").click(initiate_geolocation);
});
function initiate_geolocation(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(handle_geolocation_query, handle_errors);
} else{
yqlgeo.get('visitor', normalize_yql_response);
}
}
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 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 handle_geolocation_query(position){
var image_url ="http://maps.google.com/maps/api/staticmap?sensor=false¢er=" + position.coords.longitude + ',' + position.coords.longitude + "&zoom=14&size=300x400&markers=color:blue|label:S|" +
position.coords.latitude + ',' + position.coords.longitude;
$("#map").remove();
$(document.body).append(
$(document.createElement("img")).attr("src", image_url).attr('id', 'map')
);
alert('Lat:' + position.coords.latitude + ' ' +
'Lon: ' + position.coords.longitude);
}
</script>
</head>
<body>
<div>
<button id="btnInit">Find my location</button>
</div>
<body>
</html>