
Problema con API de geolocalización
Publicado por Juan (2 intervenciones) el 26/09/2016 17:57:45
Hola llevo un tiempo con varios errores que tengo pero no me cruzo con nadie que comprenda lo que hablo, asi que vengo aqui en busca de ayuda y en ayudar en lo que pueda .
Este Error lo que me ocurre que al ejecutar function recupera_geo( no consigo que la web me de el aviso para usar la posicion en el mapa solo me dice no se a permitido la posicion al usuario como que me deniega el acceso sin pedirme si quiere o no usar mi ubicacion , no se si me explicado bien lo que necesito es que en el mapa el usuario pueda decir donde esta en ese momento espero respuestas gracias.
Este Error lo que me ocurre que al ejecutar function recupera_geo( no consigo que la web me de el aviso para usar la posicion en el mapa solo me dice no se a permitido la posicion al usuario como que me deniega el acceso sin pedirme si quiere o no usar mi ubicacion , no se si me explicado bien lo que necesito es que en el mapa el usuario pueda decir donde esta en ese momento espero respuestas gracias.
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
<script type="text/javascript">
function geo_desde_posiciones(){
var vlat = 17.9910724;
var vlong = -0.1064417;
if (document.getElementById('latitud').value != 0){
vlat = document.getElementById('latitud').value;
vlong = document.getElementById('longitud').value;
}
var localizacion = new google.maps.LatLng(vlat, vlong);
var opciones = {
zoom: 15,
center: localizacion,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var div = document.getElementById('mapa');
var map = new google.maps.Map(div, opciones);
var infowindow = new google.maps.InfoWindow({
content: ''
});
var marcadores = [
{
position:{
lat : vlat,
lng : vlong
}
}
];
for (var i = 0, j = marcadores.length; i < j; i++) {
var contenido = marcadores[i].contenido;
var marker = new google.maps.Marker({
position: new google.maps.LatLng(marcadores[i].position.lat, marcadores[i].position.lng),title: 'AQUI ',
map: map,
draggable: <?php if ($obj_actual->attr->latitud == ""){echo "true";}else{ echo "false";};?>
});
<?php if ($obj_actual->attr->latitud == ""){ ?>
(function(marker, contenido){
google.maps.event.addListener(marker, 'click', function(marker){
vlat=marker.latLng.lat();
vlong=marker.latLng.lng();
document.getElementById('latitud').value = vlat;
document.getElementById('longitud').value = vlong;
geo_desde_posiciones();
});
})(marker,contenido);
<?php } ?>
}
google.maps.event.addListener(map,'click',function(event) {
vlat=event.latLng.lat();
vlong=event.latLng.lng();
recupera_click(vlat,vlong);
});
google.maps.event.addDomListener(window, "resize", function() {
var center = map.getCenter();
google.maps.event.trigger(map, "resize");
map.setCenter(center);
});
}
</script>
<script type="text/javascript">
function recupera_direccion(){
GMaps.geocode({
address: $('#geo_direccion').val().trim(),
callback: function(results, status){
if(status=='OK'){
var latlng = results[0].geometry.location;
vlat=latlng.lat();
vlong=latlng.lng();
document.getElementById('latitud').value = vlat;
document.getElementById('longitud').value = vlong;
geo_desde_posiciones();
}
}
});
}
function recupera_geo(){
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(function(objPosition)
{
var vlat = objPosition.coords.latitude;
var vlong = objPosition.coords.longitude;
document.getElementById('latitud').value = vlat;
document.getElementById('longitud').value = vlong;
geo_desde_posiciones();
}, function(objPositionError)
{
switch (objPositionError.code)
{
case objPositionError.PERMISSION_DENIED:
alert ('No se ha permitido el acceso a la posicion del usuario.');
break;
case objPositionError.POSITION_UNAVAILABLE:
alert ("No se ha podido acceder a la información de su posición.");
break;
case objPositionError.TIMEOUT:
alert ("El servicio ha tardado demasiado tiempo en responder.");
break;
default:
alert ("Error desconocido.");
}
}, {
maximumAge: 75000,
timeout: 15000
});
}
else
{
alert ("Su navegador no soporta la API de geolocalización.");
}
}
$("div#mapa").resize(function() {
geo_desde_posiciones();
});
</script>
Valora esta pregunta


0