javascript - Google maps, passing "map" to a different event -


i have 2 different events, please correct me if doing wrong,

    //initializing map     google.maps.event.adddomlistener(window, 'load', initialize);      //initializing markers     google.maps.event.addlistener(map, 'idle', showmarkers); 

the first event initialize map (set up), second event querying database new markers when current map bounds change (not functional yet)

since have defined "map" inside initialize function, how can access outside function , pass second event? can see have declared before functions global variable still undefined event argument, have been stuck on days

var map; function initialize(){         //defining map options         var maplatlng = new google.maps.latlng(37.09024, -100.712891);         var mapoptions = {             zoom: 4,             center: maplatlng         }         //defining map         map = new google.maps.map(document.getelementbyid('map-canvas'), mapoptions);     }      function showmarkers(){          parse.initialize("x","x");          var query = new parse.query("business_and_reviews");         var results = new parse.object("business_and_reviews");          query.equalto("name","mcdonalds");          query.find({             success: function(results) {                 console.log(results);                  (var = 0; < results.length; i++) {                     var object = results[i];                 }                  var lat = (object["attributes"]["lat"]);                 var lng = (object["attributes"]["lng"]);                  console.log(lat);                 console.log(lng);                  //adding marker query                 var marker = new google.maps.marker({                     position: maplatlong,                     map: map,                     title: 'hello world!'                 });              },             error: function(object, error) {             }         });      }     //initializing map     google.maps.event.adddomlistener(window, 'load', initialize);      //initializing markers     google.maps.event.addlistener(map, 'idle', showmarkers); 

for second event "map" undefined

solved it! put idle event listener inside initialize function , works charm! guess initilize isn't initialize page runs constantly


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -