为什么我会遇到此GeoCode错误

时间:2017-03-04 02:11:18

标签: php wordpress google-maps google-maps-api-3

当我尝试在我的网站上发帖时,这就是我所得到的。我需要做些什么才能修复?

  

警告:file_get_contents(http://maps.google.com/maps/api/geocode/json?address=):无法打开流:HTTP请求失败!第351行/home/dfwwrightimc/public_html/wp-content/themes/visitdfw/functions.php中的HTTP / 1.0 400错误请求

Sub RowFinder()
    Dim rng As Range, j As Long, lastCell As Range, ar
    ar = Array("Charge", "Discharge")
    j = 2
    With Sheets("General Text")
        Set lastCell = .Cells(.Rows.Count, "G").End(xlUp)
        Set rng = .Range("G1", lastCell)
        On Error GoTo Finished
        Do
            .Cells(j, "B").value = rng.row - 1 + Application.Match(ar(j Mod 2), rng, 0)
            Set rng = .Range("G" & .Cells(j, "B").value, lastCell)
            j = j + 1
        Loop
    End With
Finished:
End Sub

2 个答案:

答案 0 :(得分:0)

更改以下行:

$address1 = str_replace(" ","+",$address);
$address1 = str_replace("&","%26",$address1);
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address1");

$address1 = urlencode ( $address );
$json = file_get_contents("http://maps.google.com/maps/api/geocode/json?address=$address1");

再试一次。

说明:错误Bad Request与错误的网址相关。

urlencode — URL-encodes string

string urlencode ( string $str )

当编码要在URL的查询部分中使用的字符串时,此函数很方便,这是将变量传递到下一页的便捷方式。

答案 1 :(得分:0)

检查您如何调用geo_lat_long()功能。地址是否正确传递?由于错误消息中的网址以?address=结尾,没有任何值,因此$address1似乎为空。