将数组传递到urlencode

时间:2018-12-08 13:12:16

标签: php

尝试获取谷歌地图的经纬度,并使用以下代码。

    $links = [$url1, $url2, $url3];
    $addr = [];
    foreach($links as $link){

        $htm = pageContent($link);
        $paths = new \DOMXPath($htm);
        $routes = $paths->query("table[@class='bgc_line']/tr[3]/td[2]");
        foreach ($routes as $route) {
            $addr = trim($route->nodeValue);
        }

            $address = urlencode($addr);
            $response = file_get_contents("https://maps.googleapis.com/maps/api/geocode/json?address={$address}&key=GOOGLE_API_KEY");
            $result = json_decode($response);

            $lat[] = $result->results[0]->geometry->location->lat;
            $lng[] = $result->results[0]->geometry->location->lng;
        }

但是遇到urlencode() expects parameter 1 to be string, array given错误,无法将数组传递给urlencode吗?

0 个答案:

没有答案