forked from ValeFCF/firefox_app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
maps.html
138 lines (111 loc) · 3.94 KB
/
maps.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
<!DOCTYPE html>
<html>
<head>
<title>Localizador</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<meta charset="UTF-8">
<style>
body{
font-family: "Helvetica Neue", "Helvetica", Arial, Verdana, sans-serif;
}
</style>
</head>
<body>
<header>
</header>
<section>
<article>
<div id='map_canvas' style='width:100%; height:300px;'></div>
</article>
<div id="respuesta">
</div>
</section>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
var map;
var latitud;
var longitud;
var precision;
var lugares=
[
//Linea 1
[19.3982575,-99.2003524]
];
$(document).ready(function() {
localizame();
});
function localizame() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(coordenadas, errores);
}else{
alert('Oops! Tu navegador no soporta geolocalización. Bájate Chrome, que es gratis!');
}
}
function coordenadas(position) {
latitud = position.coords.latitude;
longitud = position.coords.longitude;
precision = position.coords.accuracy;
cargarMapa();
}
function errores(err) {
if (err.code == 0) {
alert("Oops! Algo ha salido mal");
}
if (err.code == 1) {
alert("Oops! No has aceptado compartir tu posición");
}
if (err.code == 2) {
alert("Oops! No se puede obtener la posición actual");
}
if (err.code == 3) {
alert("Oops! Hemos superado el tiempo de espera");
}
}
function cargarMapa() {
var latlon = new google.maps.LatLng(latitud,longitud);
var myOptions = {
zoom: 6,
center: new google.maps.LatLng(latitud,longitud),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map($("#map_canvas").get(0), myOptions);
var coorMarcador = new google.maps.LatLng(latitud,longitud);
var marcador = new google.maps.Marker({
position: coorMarcador,
map: map,
title: "Dónde estoy?"
});
var coorMetro= cercano (coorMarcador,lugares);
var marcadorM = new google.maps.Marker({
position: coorMetro,
map: map,
title: "Metro"
});
var intermedio = google.maps.geometry.spherical.interpolate(coorMarcador, coorMetro, 0.5);
map.setCenter(intermedio); // edit this line
var bounds = new google.maps.LatLngBounds();
bounds.extend(marcadorM.getPosition());
bounds.extend(marcador.getPosition());
map.fitBounds(bounds);
}
function cercano(my_position, points)
{
var inicio= my_position;
var destino= new google.maps.LatLng(points[0][0],points[0][1]);
var disInicial=new google.maps.geometry.spherical.computeDistanceBetween(inicio,destino);
for(i=1; i<points.length; i++)
{
var temp=new google.maps.geometry.spherical.computeDistanceBetween(new google.maps.LatLng(points[i][0],points[i][1]));
if(temp<disInicial)
{
destino=new google.maps.LatLng(points[i][0],points[i][1]);
disInicial=temp;
}
}
return destino;
}
</script>
</body>
</html>