0
J'ai essayé tout ce que je pouvais penser, mais la première fois que la page se charge, j'ai une image google grey, après le rafraîchissement fonctionne.Google maps. Image vide
<script>
var latitude,longitude;
function GetLocationInstant() {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': '7521 Reindeer Ct, Las Vegas, NV 89147' /* This address will come from a post variable*/ }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
latitude = results[0].geometry.location.lat();
longitude = results[0].geometry.location.lng();
// console.log("Latitude: " + latitude + "\nLongitude: " + longitude);
} else {
console.log("geocoder.geocode() failed.<?php echo $address; ?>");
}
});
};
var map;
function initializeInstant() {
var image = "http://example.com/wp-content/themes/mytheme/icon.gif";
// console.log(latitude,longitude);
var myLatlng = new google.maps.LatLng(latitude,longitude);
var mapOptions = {
zoom: 20,
center: myLatlng,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.SATELLITE
};
map = new google.maps.Map(document.getElementById("map-canvas"),mapOptions);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
icon: image
});
}
GetLocationInstant();
if ('undefined'!==latitude&&'undefined'!==longitude)
google.maps.event.addDomListener(window, "load", initializeInstant);
</script>
<div style="height: 200px;margin-bottom: 20px;padding: 0px" id="map-canvas"></div>
Comment puis-je obtenir l'image d'une carte google recherche par adresse?
EDIT: http://jsfiddle.net/qzygw4jL/4/
avez-vous vérifié la console de votre navigateur pour toutes les erreurs? –
il n'y a pas d'erreurs. – Alqin
Votre code n'est pas terminé. Copié et collé votre code sur un [exemple JsFiddle] (http://jsfiddle.net/qzygw4jL/) et il semble qu'il manque les google apis. –