PHPでGoogle Maps APIのジオコーディングを使う

<?php
    //場所名から緯度経度を得る
    function place2location($place) {
        $p = urlencode($place);
        $url = "http://maps.google.com/maps/api/geocode/json?address=$p&sensor=false";

        $request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
        $request->setHeader("user-agent", "Uhehehe! (PHP 5.2.6)");
        $response = $request->send();

        if ($response->getStatus() == 200) {
            $body = $response->getBody();
            $obj = json_decode($body);
            //先頭1件を採用
            $location = $obj->results[0]->geometry->location;
            var_dump($location);
            echo "location is OK<br>";
            return $location;
        }
    }
    
    //緯度経度から住所を得る
    function location2address($location) {
        $lat = $location->lat;
        $lng = $location->lng;
        $url = "http://maps.google.com/maps/api/geocode/json?latlng=$lat,$lng&sensor=false&language=ja";

        $request = new HTTP_Request2($url, HTTP_Request2::METHOD_GET);
        $request->setHeader("user-agent", "Uhehehe! (PHP 5.2.6)");
        $response = $request->send();

        if ($response->getStatus() == 200) {
            $body = $response->getBody();
            $obj = json_decode($body);
            echo "<h1>address</h1>";
//            var_dump($obj);
            $address = $obj->results[0]->address_components;
            var_dump($address);
            return $address;
        }
    }
    
    //場所名から住所を得る
    function place2address($place) {
        echo "point1<br>";
        $location = $this->place2location($place);
        echo "point2<br>";
        echo "point3<br>";
        $address = $this->location2address($location);
        var_dump($address);
        echo "point4<br>";
        return $address;
    }
?>