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
|
var geocoderp = new google.maps.Geocoder();
var geocoders = new google.maps.Geocoder();
var latp = 0.0;
var lngp = 0.0;
var lats = 0.0;
var lngs = 0.0;
var map;
$(document).ready(function() {
initialize();
codeAddress();
display();
});
function initialize(add1, add2) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(47.2214229,5.9680312 );
var myOptions = {
zoom: 4,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("EmplacementDeMaCarte"), myOptions);
//On récupère les coordonnées de l'adresse de la personne
codeAddress(add1, add2);
}
function codeAddress(dpt, dst) {
if (geocoderp) {
geocoderp.geocode( { 'address': dpt}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
latp = results[0].geometry.location.lat();
lngp = results[0].geometry.location.lng();
alert ("Verif : " + latp + ", " + lngp);
//sleep(500);
//Pour le debuguage de lappli
var marke = new google.maps.Marker({
position: coordonnee,
map: map,
title: "adress"
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
alert("OK");
//sleep(500);
if (geocoders) {
geocoders.geocode( { 'address': dst}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
lats = results[0].geometry.location.lat();
lngs = results[0].geometry.location.lng();
alert ("Verif : " + lats + ", " + lngs);
//sleep(500);
//Pour le debuguage de lappli
var marke = new google.maps.Marker({
position: coordonnee,
map: map,
title: "adress"
});
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
}
alert("lat depart : " + latp + " long depart : " + lngp + " lat dest : " + lats + " long dest : " + lngs);
//sleep(500);
display(latp, lngp, dpt, lats, lngs, dst);
}
function display(latp, lngp, dpt, lats, lngs, dst) {
var tableauLieux = [
[dpt, latp, lngp, "Depart"],
[dst, lats, lngs, "Destination"]
];
var optionsCarte = {
zoom: 4,
mapTypeId: google.maps.MapTypeId.HYBRID
};
var maCarte = new google.maps.Map(document.getElementById("EmplacementDeMaCarte"), optionsCarte);
var infobulle = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < tableauLieux.length; i++) {
var Lieu = tableauLieux[i];
var pointLieu = new google.maps.LatLng(Lieu[1], Lieu[2]);
bounds.extend(pointLieu);
var marqueurLieu = new google.maps.Marker({
position: pointLieu,
map: maCarte,
title: Lieu[0],
contenuInfoBulle: Lieu[3]
});
google.maps.event.addListener(marqueurLieu, "click", function() {
infobulle.setContent(this.contenuInfoBulle);
infobulle.open(maCarte,this);
});
}
maCarte.fitBounds(bounds);
}
/*function sleep(milliseconds) {
var start = new Date().getTime();
for (var i = 0; i < 1e7; i++) {
if ((new Date().getTime() - start) > milliseconds){
break;
}
}
}*/ |
Partager