2.3 Code de l'api
googlemap
<scriptsrc="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>// Code de l'api googlemap qui
récupère les coordonnés d'un point choisi
var x=36.2432373;
var y=6.5654465;
var center = new google.maps.LatLng(x,y);
var map;
function initialize() {
// Create the map.
varmapOptions = {
zoom: 15,
center: center,
mapTypeId: google.maps.MapTypeId.TERRAIN
};
map = new
google.maps.Map(document.getElementById('map-canvas'), mapOptions);
google.maps.event.addListener(map, 'click', function(event)
{
z= event.latLng;
placeMarker(z);
});
}
google.maps.event.addDomListener(window, 'load',
initialize);
google.maps.event.addListener(map, 'click', function(event)
{
placeMarker(event.latLng);
});
var marker;
functionplaceMarker(location) {
if(marker){ //on vérifie si le marqueur existe
marker.setPosition(location); //on change sa position
}else{
marker = new google.maps.Marker({ //on créé
le marqueur
position: location,
map: map
});
}
document.getElementById("latitude").value=location.lat();
document.getElementById("Longitude").value=location.lng();}
</script>
<script type="text/javascript">// Code de l'api
googlemap qui récupère les coordonnés d'une ville
choisie
vargeocoder;
function initialize() {
geocoder = new google.maps.Geocoder();
}
functioncodeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address},
function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
document.getElementById("Latitude").value=results[0].geometry.location.lat();
document.getElementById("Longitude").value=results[0].geometry.location.lng();
document.getElementById("Latitude1").value=results[0].geometry.location.lat();
document.getElementById("Longitude1").value=results[0].geometry.location.lng();
}}) ; }
</script>
<script>//Code de l'api googlemap qui
récupère les coordonnés de la position actuelle
functiongetLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation non supporter sur ce
navigateur.";
}}
functionshowPosition(position) {
document.getElementById("address").value = "";
document.getElementById("Latitude").value =
position.coords.latitude;
document.getElementById("Longitude").value =
position.coords.longitude;
document.getElementById("Latitude1").value =
position.coords.latitude;
document.getElementById("Longitude1").value =
position.coords.longitude;}
</script>
|