javascript - JQuery, Google Maps : "Cannot call methods on gmap prior to initialization" -
i have problem i've been trying figure out while now.
there's block of code works fine, if add jquery in it, crash everything.
i following error : "uncaught cannot call methods on gmap prior initialization; attempted call method 'addmarker"
the faulty code starts "$.each(markerslist.markers,"
any point me out in right direction appreciated. !
function initialize() { var myoptions = { zoom: 7, maptypeid: google.maps.maptypeid.roadmap }; map = new google.maps.map(document.getelementbyid("map_canvas"), myoptions); $.each(markerslist.markers, function(map, marker) { var destination = (marker.lat + ', ' + marker.lng); $('#map_canvas').gmap('addmarker', { 'position': new google.maps.latlng(marker.lat, marker.lng), 'title': marker.title }, function(map, marker) { $('#map_canvas').gmap('addinfowindow', { 'content': null }, function(iw) { $(marker).click(function() {iw.open(map, marker); map.panto(marker.getposition()); $('#to').val(destination); alert("you've selected " + marker.title + " destination. please enter origin"); }); }); }); }); if (navigator.geolocation) { browsersupportflag = true; navigator.geolocation.getcurrentposition(function(position) { initiallocation = new google.maps.latlng(position.coords.latitude, position.coords.longitude); contentstring = "your location found , has been added starting point."; map.setcenter(initiallocation); $('#from').val(initiallocation); }, function() { handlenogeolocation(browsersupportflag); });
i had similar issue mine, did create initialize function separate function rest of code, when page loads call initialize() , @ end of function call searchlocations() adds of markers map.
Comments
Post a Comment