I want to load a local JSON file with config information for usage in my JAVASCRIPT file.
I tried this:
var map;
var initialMapCoordinates = "";
function loadConfigFile() {
$.getJSON('js/config.json', function(jd) {
initialMapCoordinates = jd.googleMaps.initialCoordinates;
initMap();
});
};
function initMap() {
google.maps.visualRefresh = true;
var mapOptions = {
center: new google.maps.LatLng(initialMapCoordinates),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var mapElement = document.getElementById('map');
map = new google.maps.Map(mapElement, mapOptions);
}
google.maps.event.addDomListener(window, 'load', loadConfigFile());
I want to assign the different elements of the config file to variables to use them then in my script. There I still fail. I tried to use a global variable, but I seem to do something wrong here.
How do I get the contents of jd.googleMaps.initialCoordinates
into a variable to work with outside the function?