2017-06-01 18 views
0

我正在开发一个简单的Android应用程序,使用phonegap发送谷歌地图地理编码API请求与拉,局域网的位置并返回一个地址。 使用我的桌面时,一切正常! 一旦我使用adobe phonegap云构建器构建应用程序,它不起作用。此外,我无法调试,因为应用程序上没有提供任何内容。它只是显示一个空值。Phonegap谷歌地图API查询不工作

这可能是一个CORS问题? HTTPS?使用移动用户代理进行谷歌地图请求的一些问题?我不确定。感谢任何帮助!

这是我的代码:

function maps_api(latlng){ 
    var divdata = $('div#data'); 
    divdata.text('cleared'); 
    updateStatus('Starting google api: '); 
    var xhttp = new XMLHttpRequest(); 
    xhttp.onreadystatechange = function() { 
     if (this.readyState == 4 && this.status == 200) { 
      updateStatus(this.responseText); 
      var myArr = JSON.parse(this.responseText); 
      var divdata = $('div#data'); 
        divdata.text(myArr["results"][0]["formatted_address"]); 

     } 
     else 
     { 
      updateStatus(this.responseText); 
      var divdata = $('div#data'); 
      divdata.text(xhttp.statusText); 

     } 
    }; 

    xhttp.open("GET", "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + latlng + "&key=myprivatekey", true); 
    xhttp.send(); 



    } 

回答

0

我设法通过安装在白名单中,插​​件,并允许通信谷歌地图的服务器

来解决这个