mercredi 28 janvier 2015

Google map API theme option page not displaying


I'm having some issues with the integration of a google map in my web site which can geocode an address before displaying the map with the correct location.


So i have a script (it worked when i was in localhost but since i put the web site online nothing happens) :



<script src="http://ift.tt/Ylci2T"></script>
<script>
var geocoder;
var map;
var firstLoc;

function FindAddress() {
geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address' : document.getElementById('address_field').value},
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
firstLoc = results[0].geometry.location;
map = new google.maps.Map(document.getElementById("map-location"),
{
center: firstLoc,
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP
});

var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
}
else {
alert('Geocode failed: ' + status);
}
}
);
}
google.maps.event.addDomListener(window, 'load', trouverAdresse);
</script>


So i put an address in a field in my theme option page then i register the value and put it in a hidden input in my front-end and try to get it with geocoder.geocode( { 'address' : document.getElementById('address_field').value}


Seems to have a problem with geocoding, i tested with a simple script with a fix position and it showed fine.


In case you need it this is how i display the map in the front-end :



<div class="contact-map">
<div id="map-location"></div>
<form class="adresse-hidden">
<?php echo "<input id='adresse' type='text' value= '{$content_options['geolocal_setting']}'/>"?>
</form>
</div>




Aucun commentaire:

Enregistrer un commentaire