I am trying to use a timer in my javascript to poll certain data every 5seconds from my other objects in cshtml and update it into the function in javascript.
i have explored with the following code but it seems to throw the error of initialize is undefined
function initialize() {
var mapProp = {
center: new google.maps.LatLng(51.508742, -0.120850),
zoom: parseInt(5),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap")
, mapProp);
}
$(document).ready(function () {
initialize();
});
window.setInterval(function () {
/// call your function here
initialize();
}, 5000);
However, this works perfectly fine
function initialize() {
var mapProp = {
center: new google.maps.LatLng(51.508742, -0.120850),
zoom: parseInt(5),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap")
, mapProp);
}
$(document).ready(function () {
initialize();
});
As i want to make the variables global such that i can update the focus on the map every 5 seconds, i have tried to make it a global variable
var mapProp = {
center: new google.maps.LatLng(51.508742, -0.120850),
zoom: parseInt(5),
mapTypeId: google.maps.MapTypeId.ROADMAP
};
However, it seems that the script keeps on giving me an error of google is undefined.
Is there anyway i could resolve my problem.
For example i would like to update the parameters in new google.maps.LatLng(51.508742, -0.120850) every 5 seconds.
varkeyword inside a function then it's not a global variable, it's scoped to that function.window.myVariable = "something";