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
| <script>
"use strict"; // force la déclaration des variables
var Carte, OldInfWindow
//*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*
function ChoixMap(input)
{
switch (input.value)
{
case 'TERRAIN':
Carte.setMapTypeId(google.maps.MapTypeId.TERRAIN);
break;
case 'ROADMAP':
Carte.setMapTypeId(google.maps.MapTypeId.ROADMAP);
break;
case 'SATELLITE':
Carte.setMapTypeId(google.maps.MapTypeId.SATELLITE);
break;
case 'HYBRID':
Carte.setMapTypeId(google.maps.MapTypeId.HYBRID);
}
}
//*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*
function initMap()
{
var mapCanvas;
mapCanvas = document.getElementById("MaCarte");
var mapOptions =
{center: new google.maps.LatLng(46.0228868,6.6066035),
mapTypeControl: false,
zoom: 12,
mapTypeId: google.maps.MapTypeId.TERRAIN};
Carte = new google.maps.Map(mapCanvas,mapOptions);
//Ajouter un écouteur pour l'événement click ou rightclick sur la carte,
//pour affichage de l'adresse, l'altitude, la latitude et la longitude.
Carte.addListener('click', function(event){displayLocationElevation(event.latLng)});
}
//*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*
function displayLocationElevation(location)
{ if (typeof(OldInfWindow) != 'undefined') OldInfWindow.close();// permet de fermer l'infos precedante
var MyArr = String(location);
var CvString = MyArr.replace("(",""); CvString = CvString.replace(")","");
var Tbl = CvString.split(",");
var latlng = {lat: parseFloat(Tbl[0]), lng: parseFloat(Tbl[1])};
var Latitude = Math.round(Tbl[0]*100)/100;
var Longitude = Math.round(Tbl[1]*100)/100;
var InfText1, InfText2;
//------------------------------------------------------------------------------------------------------------
var geocoder = new google.maps.Geocoder;
//Lancer la requête pour recuperer l'adresse, code postal, ville et pays
geocoder.geocode({'location': latlng}, function(results, status)
{
if (status === google.maps.GeocoderStatus.OK)
{
if (results[1]) //Récupérer le deuxieme element
{
CvString = results[1].formatted_address;
InfText1 = CvString.replace("Unnamed Road,", " ");
ActuAffichage(InfText1,InfText2,location);
}else{
alert('Aucun résultat trouvé')
}
}else{
alert('Geocodeur échec dû à: ' + status);
}
})
//------------------------------------------------------------------------------------------------------------
var elevator = new google.maps.ElevationService;
//Lancer la requête pour recuperer l'altitude
elevator.getElevationForLocations({'locations': [location]}, function(results, status)
{
if (status === google.maps.ElevationStatus.OK)
{
if (results[0]) //Récupérer le premier element
{
var Altitude = Math.round(results[0].elevation);
InfText2 = "Altitude: " + Altitude + "M.<br> Latitude: " + Latitude + "°<br> Longitude: " + Longitude + "°";
ActuAffichage(InfText1,InfText2,location);
}else{
alert('Aucun résultat trouvé')
}
}else{
alert('Echec dû à: ' + status);
}
})
}
//*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*
function ActuAffichage(Data1,Data2,location)
{
if (typeof(Data1) != 'undefined')
{
if (typeof(Data2) != 'undefined')
{
//alert('A que coucou');
var infowindow = new google.maps.InfoWindow({map: Carte});
OldInfWindow = infowindow;
infowindow.setContent("<h4>" + Data1 + "</h4>" + Data2);
infowindow.setPosition(location);
}
}
}
//*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*--*
</script> |
Partager