【问题标题】:PHP geocode is working on localhost but not on serverPHP地理编码在本地主机上工作,但不在服务器上
【发布时间】:2014-08-21 21:25:32
【问题描述】:

是的,在我将所有内容转移到我的主机之前,这一切都运行良好,现在这不起作用

这段代码有什么问题,我需要在我的主机上配置一些东西吗?

这里是 php,它使用 google maps api

function getlatlang($location)  
 {  
      $geocode = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='. urlencode($location) .'&sensor=false');  

      $output= json_decode($geocode);  

      return $output->results[0]->geometry->location;  
 }  

 $objlocation = getlatlang($postcode);  
 $latitude = $objlocation->lat;  
 $longitude = $objlocation->lng; 

我还打开了错误报告 E_ALL,但没有显示任何内容,所以我尝试了 -1,它给出了以下错误。但是我在本地主机上从来没有遇到过这些错误

Notice: Undefined offset: 0 in /websites/123reg/LinuxPackage22/fa/gs/an/fagsandbooze.com/public_html/test.php on line 14

Notice: Trying to get property of non-object in /websites/123reg/LinuxPackage22/fa/gs/an/fagsandbooze.com/public_html/test.php on line 14

Notice: Trying to get property of non-object in /websites/123reg/LinuxPackage22/fa/gs/an/fagsandbooze.com/public_html/test.php on line 14

Notice: Trying to get property of non-object in /websites/123reg/LinuxPackage22/fa/gs/an/fagsandbooze.com/public_html/test.php on line 18

Notice: Trying to get property of non-object in /websites/123reg/LinuxPackage22/fa/gs/an/fagsandbooze.com/public_html/test.php on line 19

【问题讨论】:

  • 完整的错误检查和显示在 ?还有var_dump($output)
  • 将 error_reporting 转为 E_ALL 并查看是否有任何错误。对来自 file_get_contents 的响应进行 var_dump 以查看您是否获得了预期的响应。
  • 就是我所说的 :-)\
  • 看看,我编辑了帖子:)
  • 返回行是 14 ?所以转储输出的值,它不是你认为的那样

标签: php google-maps localhost geocoding


【解决方案1】:

始终检查本地主机和主机上的 php 版本是否相同。地理编码器仅适用于 php >= 7.1 https://github.com/geocoder-php/GeocoderLaravel

【讨论】:

    【解决方案2】:

    结果我超出了我的日常要求。哎呀!

    object(stdClass)#1 (3) { ["error_message"]=> string(56) "You have exceeded your daily request quota for this API." ["results"]=> array(0) { } ["status"]=> string(16) "OVER_QUERY_LIMIT" } 
    

    【讨论】:

    • 您的服务器是否在共享主机上?其他人可能已经用完了配额(您没有使用密钥...)。
    猜你喜欢
    • 2013-04-28
    • 2016-08-04
    • 2014-01-15
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2013-04-14
    • 2020-12-07
    • 2019-08-18
    相关资源
    最近更新 更多