-
Notifications
You must be signed in to change notification settings - Fork 1
/
indexAPI2.html
90 lines (76 loc) · 2.59 KB
/
indexAPI2.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
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function loadMap(idMapCanvas, latitude, longitude, accuracy) {
var latlng = new google.maps.LatLng(latitude, longitude);
var optionsMap = {
zoom : 15,
center : latlng,
mapTypeId : google.maps.MapTypeId.HYBRID
};
var map = new google.maps.Map(document.getElementById(idMapCanvas), optionsMap);
var optionsCircle = {
center : latlng,
map : map,
radius : parseInt(accuracy),
clickable : false,
fillColor : "#00AAFF",
fillOpacity : 0.3,
strokeColor : "#057CB8",
strokeOpacity : 0.8,
strokeWeight : 1
};
var circle = new google.maps.Circle(optionsCircle);
var infowindow = new google.maps.InfoWindow();
infowindow.setContent(latitude + ", " + longitude);
var optionsMarker = {
position : latlng,
flat : true,
title : latlng.toString(),
map : map
};
var marker = new google.maps.Marker(optionsMarker);
var latlng2 = new google.maps.LatLng(latitude - 0.001, longitude - 0.001);
optionsMarker = {
position : latlng2,
flat : true,
title : latlng2.toString(),
map : map
};
var marker2 = new google.maps.Marker(optionsMarker);
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
}
function initGeolocation() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
function onSuccess(position){
document.getElementById('loading').style.display = "none";
loadMap("map_canvas", position.coords.latitude, position.coords.longitude, position.coords.accuracy);
}
function onError(error)
{
document.getElementById('loading').style.display = "none";
switch(error.code)
{
case error.PERMISSION_DENIED: alert("No se ha permitido compartir los datos de geolocalización");
break;
case error.POSITION_UNAVAILABLE: alert("No se puede detectar la posición actual");
break;
case error.TIMEOUT: alert("Se ha superado el tiempo de espera");
break;
default: alert("Error desconocido");
break;
}
}
</script>
</head>
<body onload="initGeolocation()">
<span id="loading">Cargando...</span>
<div id="map_canvas" style="width: 500px; height: 500px;"></div>
</body>
</html>