Je suis en train de géocodage un nom de lieu, mais quand je lance la fonction, je reçois,Google maps v3 géocodage
« une chaîne vide » dans ma console,
ci-dessous est mon code pourquoi serait-ce se passer?
function getLatLong(address)
{
var geocoder = new google.maps.Geocoder();
var result = "";
geocoder.geocode({ 'address': address, 'region': 'uk' }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
result = results[0].geometry.location;
} else {
result = "Unable to find address: " + status;
}
});
console.log(result);
}
MISE À JOUR
Ok, donc j'ai ma valeur d'utilité à la console, maintenant quand je tente de pousser la valeur de l'élément dans la fonction, je reçois définie comme un retour, ci-dessous le code complet,
function getLatLong(address)
{
var geocoder = new google.maps.Geocoder();
var result = "";
geocoder.geocode({ 'address': address, 'region': 'uk' }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
result = results[0].geometry.location;
return result;
} else {
result = "Unable to find address: " + status;
alert(result);
}
});
}
//getLatLong("YORK");
function loadScript(postcode){
alert(postcode);
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=initialize?"+postcode;
document.body.appendChild(script);
}
/* load map on visitors location */
function initialize(postcode){
var myLatlng = new google.maps.LatLng(getLatLong(postcode));
var myOptions = {
center: myLatlng,
zoom:13,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById('map'), myOptions);
google.maps.event.trigger(map, 'resize');
map.setZoom(map.getZoom());
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon:'http://google-maps-icons.googlecode.com/files/home.png',
});
}
Et on l'appelle comme ça,
$(function(){
$("dd a, dt a").live("click", function(){
var self = $(this);
$("#overlay").fadeIn('slow');
var targetProcent = 85;
var targetWidth = $(window).width() * (targetProcent/100);
var targetHeight = $(window).height() * (targetProcent/100);
var targetX = ($(window).width() - targetWidth)/2;
var targetY = ($(window).height() - targetHeight)/2 + $(document).scrollTop();
$('#lightbox').height(700);
$('#lightbox').width(targetWidth);
$('#lightbox').load(self.attr("href"));
loadScript($("#postcode").val());
//usePointFromPostcode(document.getElementById('postcode').value, placeMarkerAtPoint)
$('#lightbox').css({
"position": "absolute",
"top": targetY+"px",
"left": targetX+"px"
}).fadeIn('slow');
return false;
});
});
$ ("# code postal"). Val() correspond à un élément chargé lors de l'utilisation de load()
ce qui est le rappel? – Udders
changer '}); console.log (résultat); 'à ' console.log (résultat); }); ' – venimus