【问题标题】:Phonegap jQuery Mobile Google Maps API errorPhonegap jQuery Mobile 谷歌地图 API 错误
【发布时间】:2012-06-05 09:44:49
【问题描述】:

我正在尝试使用 Google Maps API 进行搜索。如果我在浏览器上打开 this 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>&nbsp;" + entry.name +
              "</h3><p><strong>&nbsp;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

【问题讨论】:

    标签: jquery jquery-mobile cordova google-maps-api-3


    【解决方案1】:

    添加

    $.mobile.allowCrossDomainPages = true; 
    

    就在之前

     `$.getJSON()` 
    

    改变

    $.mobile.changePage("list");

    $.mobile.changePage("#list");
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-03-15
      • 2016-05-09
      • 1970-01-01
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      相关资源
      最近更新 更多