G4uthier
Messages postés131Date d'inscriptiondimanche 2 décembre 2007StatutMembreDernière intervention23 juillet 2009
-
2 juin 2008 à 17:29
G4uthier
Messages postés131Date d'inscriptiondimanche 2 décembre 2007StatutMembreDernière intervention23 juillet 2009
-
3 juin 2008 à 12:08
Bonjour,
voial j'ai un probleme avec mon code :
var map;
var localSearch = new GlocalSearch();
var address2;
var address3;
var postcode;
var img;
var icon = new GIcon();
icon.image = "http://images.google.com/mapfiles/marker.png";
icon.iconSize = new GSize(20, 30);
icon.iconAnchor = new GPoint(6, 20);
icon.infoWindowAnchor = new GPoint(10, 34);
function usePointFromPostcode(postcode,callbackFunction) {
if (localSearch.results[0])
{
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
callbackFunction(point);
}else{
alert("Postcode not found!");
}
});
localSearch.execute(postcode + ", UK");
}
//function placeMarkerAtPoint(point)
//{
// var marker = new GMarker(point,icon);
// map.addOverlay(marker);
//}
function setCenterToPoint(point)
{
map.setCenter(point, 15);
var marker = new GMarker(point,icon);
map.addOverlay(marker);
map.openInfoWindow(map.getCenter(),"");
}
function showPointLatLng(point)
{
var Latitude = point.lat();
var Longitude = point.lng();
}
function mapLoad() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_NORMAL_MAP);
}
}
GDownloadUrl("http://localhost/Smart/XmlGmap.php",function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
alert("ici!!");
address2 = markers[i].getAttribute("address2");
address3 = markers[i].getAttribute("address3");
postcode = markers[i].getAttribute("postcode");
img = markers[i].getAttribute("img1");
usePointFromPostcode(postcode,createMarker);
//alert("valeur lon: "+Longitude);
//alert("valeur la: "+Latitude);
//var point = new GLatLng(Latitude,Longitude);
//var marker = createMarker(point, address2, address3, postcode,img);
}
});
function createMarker(point, address2, address3, postcode,img) {
var marker = new GMarker(point, icon);
alert(address2);
var html = " " + address3 + "
" + address2;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
map.addOverlay(marker);
//return marker;
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
function addUnLoadEvent(func) {
var oldonunload = window.onunload;
if (typeof window.onunload != 'function') {
window.onunload = func;
} else {
window.onunload = function() {
oldonunload();
func();
}
}
}
addLoadEvent(mapLoad);
addUnLoadEvent(GUnload);
Je creee mes marqueurs sur la map mais je n'arrive pas à appeler la fonction "createMarker"
avec mes parmaetres de mon xml . J'ai testé pas mal de chose mais ça marche pas. Vous avez une idée ? parce que je seche.
if (localSearch.results[0])
{
var resultLat = localSearch.results[0].lat;
var resultLng = localSearch.results[0].lng;
var point = new GLatLng(resultLat,resultLng);
callbackFunction(point, address2, address3, postcode,img);
}else{
alert("Postcode not found!");
}
});
localSearch.execute(postcode + ", UK");
}
//function placeMarkerAtPoint(point)
//{
// var marker = new GMarker(point,icon);
// map.addOverlay(marker);
//}
function setCenterToPoint(point)
{
map.setCenter(point, 15);
var marker = new GMarker(point,icon);
map.addOverlay(marker);
map.openInfoWindow(map.getCenter(),"");
}
function showPointLatLng(point)
{
var Latitude = point.lat();
var Longitude = point.lng();
}
function mapLoad() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(54.622978,-2.592773), 5, G_NORMAL_MAP);
}
}
GDownloadUrl("http://localhost/Smart/XmlGmap.php",function(data) {
var xml = GXml.parse(data);
var markers = xml.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
address2 = markers[i].getAttribute("address2");
address3 = markers[i].getAttribute("address3");
postcode = markers[i].getAttribute("postcode");
img = markers[i].getAttribute("img1");
alert("attention"+address2 );
usePointFromPostcode(postcode,createMarker);
//alert("valeur lon: "+Longitude);
//alert("valeur la: "+Latitude);
//var point = new GLatLng(Latitude,Longitude);
//var marker = createMarker(point, address2, address3, postcode,img);
}
});
function createMarker(point, address2, address3, postcode,img) {
var marker = new GMarker(point, icon);
alert(address2);
alert(address3);
alert(img);
var html = " " + address3 + "
" + address2;
GEvent.addListener(marker, 'click', function() {
marker.openInfoWindowHtml(html);
});
map.addOverlay(marker);
//return marker;
}
function addLoadEvent(func) {
var oldonload = window.onload;
if (typeof window.onload != 'function') {
window.onload = func;
} else {
window.onload = function() {
oldonload();
func();
}
}
}
function addUnLoadEvent(func) {
var oldonunload = window.onunload;
if (typeof window.onunload != 'function') {
window.onunload = func;
} else {
window.onunload = function() {
oldonunload();
func();
}
}
}
addLoadEvent(mapLoad);
addUnLoadEvent(GUnload);
Ca avance mais je comprends pas pourquoi maintenant il me cree mes markers mais ils ne contiennent que la variable address2 et deplus tous les pointeurs ont la meme valeur pour la variable address2...
Si quelqu'un voit pourquoi ca fonctionne pas je lui en serait infiniement reconnaissant...
G4uthier
Messages postés131Date d'inscriptiondimanche 2 décembre 2007StatutMembreDernière intervention23 juillet 2009 3 juin 2008 à 12:08
j'ai ciblé mon probleme c'est mon appel de focntion qui deconne.
Lorsque j'appel "usePointFromPostcode(postcode,createMarker);" et bien dans la fonction "usePointFromPostcode(postcode,callbackFunction)" ,ma callbackfonction (createMarker) est appelé lorsque ma boucle qui parcours mon XML est fini. et c'est pour
ça que je me retrouve avec mon dernier enregistrement de ma table dans mon marqueur. Il crée donc tous les marqueur en fonction du dernier enregistrement de ma table...
Une idée, pourquoi il me fait ca? vous me comprenez?