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 139 140 141 142 143 144 145 146 147 148 149 150 151 152
| var pos_name;
var pos_lat;
var pos_lon;
var pos_alt;
var pos_precision;
var pos_precision_alt;
var pos_speed;
var pos_classement;
var pos_adresse;
var infowindow = new google.maps.InfoWindow();
var geocoder;
getLocation();
function getLocation() {
geocoder = new google.maps.Geocoder();
if (navigator.geolocation) {
var optionsGeo = {
timeout: 2000,
enableHighAccuracy: true,
maximumAge: 0
};
navigator.geolocation.watchPosition(showPosition, showError, optionsGeo);
} else {
alert('Geolocation is not supported by this browser.');
}
}
function showPosition(position) {
pos_name = 'myPosition';
pos_lat = position.coords.latitude;
pos_lon = position.coords.longitude;
pos_alt = position.coords.altitude;
pos_precision = position.coords.accuracy;
pos_precision_alt = position.coords.altitudeAccuracy;
pos_speed = position.coords.speed;
pos_classement = 1;
geocoder.geocode({
'latLng': new google.maps.LatLng(pos_lat, pos_lon),
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
console.log('adresse : ' + results[1].formatted_address + ' ' + results[0].formatted_address);
pos_adresse = results[1].formatted_address;
}
} else {
console.log('Le geocodage a echoue pour la raion suivante : ' + status);
}
});
console.log('ShowPosition - Name : ' + pos_name + ', Latitude : ' + pos_lat + ', longitude : ' + pos_lon + ', altitude : ' + pos_alt + ', precision : ' + pos_precision + ', adresse : ' + pos_adresse);
googleMarker();
document.getElementById('h_user_lat').value = pos_lat;
document.getElementById('h_user_lon').value = pos_lon;
document.getElementById('h_user_acc').value = pos_precision;
document.getElementById('h_user_add').value = pos_adresse;
document.getElementById('h_user_add').value = pos_adresse;
if (typeof localStorage != 'undefined' && JSON) {
var myCoordonnees = {
lat: pos_lat,
lon: pos_lon,
alt: pos_alt,
acc: pos_precision,
speed: pos_speed
};
localStorage.setItem('myMarker', JSON.stringify(myCoordonnees));
console.log('Mémorisation myMarker effectuée');
}
else {
console.log('localStorage n\'est pas supporté');
}
}
function showError(error) {
switch (error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = 'User denied the request for Geolocation.'
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = 'Location information is unavailable.'
break;
case error.TIMEOUT:
x.innerHTML = 'The request to get user location timed out.'
break;
case error.UNKNOWN_ERROR:
x.innerHTML = 'An unknown error occurred.'
break;
}
}
function googleMarker() {
var myPosition = new google.maps.LatLng(pos_lat, pos_lon); //[pos_name, pos_lat, pos_lon, pos_classement]
console.log('sucessCallback - Name : ' + pos_name + ', Latitude : ' + pos_lat + ', longitude : ' + pos_lon + ', altitude : ' + pos_alt + ', precision : ' + pos_precision + ', adresse : ' + pos_adresse);
var options = {
disableDefaultUI: true,
zoom: 17,
center: myPosition,
//scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById('map'), options);
var myMarker = new google.maps.Marker({
position: myPosition,
map: map,
title: 'votre position',
center: new google.maps.LatLng(pos_lat, pos_lon)
});
var locations;
$.ajax({
url: '/controller/manager2.php',
type: 'POST',
data: {
t: 'Point',
a: 'get'
},
success: function () {
$.getJSON('/controller/manager2.php?a=get&t=Point&lat=' + pos_lat + '&lon=' + pos_lon + '&acc=' + pos_precision, function (data) {
//console.log('count data :' + data.length);
locations = new Array((data.length - 1));
$.each(data, function (key, val) {
//console.log('#' + val.id_i + ' =>' + val.title_i);
for (var i = 0; i <= (data.length - 1); i++)
{
console.log(val.title_it, val.lat_i, val.lon_i, val.img_it, val.id_i);
locations[i] = new Array(val.title_it, val.lat_i, val.lon_i, val.img_it, val.id_i);
}
if (typeof localStorage != 'undefined' && JSON) {
//var coordonneesPoints = {id:val.id_i,type:val.title_it,lat:val.lat_i,lon:val.lon_i};
//localStorage.setItem('marker' + i,JSON.stringify(coordonneesPoints));
localStorage.setItem('PointsMarker', JSON.stringify(locations));
console.log('Mémorisation PointsMarker effectuée');
}
else {
console.log('localStorage n\'est pas supporté');
}
console.log(locations);
var infowindow = new google.maps.InfoWindow();
var marker,
i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
title: locations[i][0],
icon: locations[i][3] //'/images/icons/icon-marker-alerte.png'
});
google.maps.event.addListener(marker, 'click', (function (marker, i) {
return function () {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
}) (marker, i));
}
});
});
}
});
}; |
Partager