google map api is loaded asynchroneously
jQuery(function($) {
// Asynchronously Load the map API
var script = document.createElement('script');
script.src = "http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize";
document.body.appendChild(script);
});
i then do
function initialize() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
// Display a map on the page
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
map.setTilt(45);
var address ="Marseille";
var geocoder;
geocoder = new google.maps.Geocoder();
var markers;
markers= geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var titlelatlong=[address,results[0].geometry.location.lat(),results[0].geometry.location.lng()];
console.log(titlelatlong);
return titlelatlong;
}
});
console.log(markers);
why
console.log(titlelatlong)
output is what i want and
console.log(markers)
is undefined ?
how can i fix this ?