Phonegap jQuery Mobile Google Maps API error -
i trying make search using google maps api. if open this url on browser (specifying api key), result displayed. using phonegap & jquery, , tried use in function:
$("#search").click(function() { try { $.mobile.showpageloadingmsg(); navigator.geolocation.getcurrentposition(function(position) { var radius = $("#range").val() * 1000; mapdata = new google.maps.latlng( position.coords.latitude, position.coords.longitude ); var url = "https://maps.googleapis.com/maps/api/place/search/json?location=" + position.coords.latitude + "," + position.coords.longitude + "&radius=" + radius + "&name=" + $("#searchbox").val() + "&sensor=true&key=api_key"; $.getjson(url, function(data) { cacheddata = data; $("#result-list").html(""); try { $(data.results).each(function(index, entry) { var htmldata = "<a href=\"#details\" id=\"" + entry.reference +"\"><img src\"" + entry.icon + "\" class=\"ui-li-icon\"/img><h3> " + entry.name + "</h3><p><strong> vicinity: " + entry.vicinity + "</strong></p></a>"; var lielem = $( document.createelement( 'li' ) ); $("#result-list").append(lielem.html( htmldata )); $(lielem).bind( "tap", function(event){ event.stoppropagation(); fetchdetails(entry); return true; }); }); $("#result-list").listview('refresh'); } catch(err) { console.log( "got error while putting search result on result page " + err ); } $.mobile.changepage("list"); $.mobile.hidepageloadingmsg(); }).error(function(xhr, textstatus, errorthrown) { console.log("got error while fetching search result : xhr.status=" + xhr.status); }).complete(function(error) { $.mobile.hidepageloadingmsg(); }); }, function(error) { console.log("got error fetching geolocation " + error); }); } catch(err){ console.log("got error on clicking search button "+ err); } }); and when testing, response on firebug console:
get https://maps.googleapis.com/maps/api/place/search/json?location=-26.1443912,28.0261926&radius=5000&name=pizza&sensor=false&key=api_key 200 ok (colored red error icon next it)<br/> got error while fetching search result: xhr.status = 0
add
$.mobile.allowcrossdomainpages = true; just before
`$.getjson()` and change
$.mobile.changepage("list");
to
$.mobile.changepage("#list");
Comments
Post a Comment