
[英]GPS tracker with jQuery mobile, PhoneGap and Google Maps
[英]Phonegap jQuery Mobile Google Maps API error
我正在尝试使用Google Maps API进行搜索。 如果在浏览器中打开此URL (指定我的API KEY),则会显示结果。 我正在使用Phonegap和jQuery,并尝试在此功能中使用它:
$("#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);
}
});
在测试时,我在萤火虫控制台上得到了以下响应:
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 with an error icon next to it)<br/>
获取搜索结果时出错:xhr.status = 0
加
$.mobile.allowCrossDomainPages = true;
就在之前
`$.getJSON()`
并改变
$.mobile.changePage("list");
至
$.mobile.changePage("#list");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.