MQ is not defined

2 posts / 0 new
Last post
shubho
MQ is not defined

 

down votefavorite

 

I need to Load the mapquestapi on a button Load after adding i am getting error as MQ is not defined

Same thing is working when i am adding the script to the head but not working on button load. i.e, $('head').append();

 

$("#viewOnMap").click(function () {

$('head').append("https://www.mapquestapi.com/sdk/leaflet/v2.2/\"mq-map.js?key=\"KEY\"></script>");

$('head').append("https://www.mapquestapi.com/sdk/leaflet/v2.2/\"mq-geocoding.js?key=\"KEY\"></script>");

var map = L.map('map', {
layers: MQ.mapLayer() ---->>> MQ is not defined
});

MQ.geocode({ map: map })
.search('lancaster pa');

});

I would be glad if anyone can post a solution to this issue. Thanks in advanced.


MQBrianCoakley
Can you see the files loading
Can you see the files loading in the developer tools network tab successfully?   Is the geocode and/or map being loaded after the files are completely loaded? If the code above is run as is then the map is being created before the files are loaded. Create an event on the file load to run processes using those files.