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
|
function geocodeAdresse()
{
addresse=document.getElementById("adresse").value;//recupére la valeur du champ adresse
geoCodeur.geocode( { 'address': addresse},//on récupére l'adresse entré par l'utisateur
function(results, status)
{
if (status == google.maps.GeocoderStatus.OK) //si on trouve une correspondance a cette adresse
{
clearOverlays();//On efface le marker precedent
point=results[0].geometry.location;
//On créé un nouveau marker
var marker = new google.maps.Marker({
map: map,
draggable:true,
position: point
});
markersArray.push(marker);//on entre le marker dans un tableau pour pouvoir l'effacer
map.setCenter(point, 12);//On centre la map
}
else
{//si on ne trouve pas de correspondance
alert("La Geolocalisation est un echec pour la raison suivante: " + status);//message d'erreur
}
}
);
}
function initialize()
{
var centreCarte = new google.maps.LatLng(45.045, 3.884);
var optionsCarte = {
zoom: 4,
center: centreCarte,
mapTypeId: google.maps.MapTypeId.ROADMAP,
mapTypeControl: false,
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
}
}
var map = new google.maps.Map(document.getElementById("gmap"), optionsCarte);
geoCodeur = new google.maps.Geocoder();//On ajoute un géocoder pour la géolocalisation
mgr = new MarkerManager(map, {trackMarkers: true, maxZoom: 15});//On ajoute un marker manager
google.maps.event.addListener(mgr, 'loaded', function() {//On charge le MarkerManager
affichemarkers(map);
mgr.refresh();
});
}
google.maps.event.addDomListener(window, 'load', initialize) |
Partager