Reputation: 413
I have figured out how to geocode an address using Zend Gdata, but I dont even know how to retrieve the pieces of JSON returned. Here is the geocoder:
include_once('Zend/Gdata.php');
$client = new Zend_Http_Client('http://maps.googleapis.com/maps/api/geocode/json');
$urlencodedAddress = urlencode('1600 Pennsylvania Avenue, N.W. Washington, DC 20500');
$client->setParameterGet('sensor', 'false');
$client->setParameterGet('address', $urlencodedAddress);
$response = $client->request('GET');
and here is the response object:
Zend_Http_Response Object ( [version:protected] => 1.1 [code:protected] => 200 [message:protected] => OK [headers:protected] => Array ( [Content-type] => application/json; charset=UTF-8 [Date] => Mon, 30 Jan 2012 03:26:25 GMT [Expires] => Tue, 31 Jan 2012 03:26:25 GMT [Cache-control] => public, max-age=86400 [Vary] => Accept-Language [Server] => mafe [X-xss-protection] => 1; mode=block [X-frame-options] => SAMEORIGIN [Connection] => close ) [body:protected] => { "results" : [ { "address_components" : [ { "long_name" : "1600", "short_name" : "1600", "types" : [ "street_number" ] }, { "long_name" : "Pennsylvania Ave NW", "short_name" : "Pennsylvania Ave NW", "types" : [ "route" ] }, { "long_name" : "Northwest Washington", "short_name" : "Northwest Washington", "types" : [ "neighborhood", "political" ] }, { "long_name" : "Washington", "short_name" : "Washington", "types" : [ "locality", "political" ] }, { "long_name" : "District of Columbia", "short_name" : "DC", "types" : [ "administrative_area_level_1", "political" ] }, { "long_name" : "United States", "short_name" : "US", "types" : [ "country", "political" ] }, { "long_name" : "20500", "short_name" : "20500", "types" : [ "postal_code" ] } ], "formatted_address" : "1600 Pennsylvania Ave NW, Washington, DC 20500, USA", "geometry" : { "location" : { "lat" : 38.89871490, "lng" : -77.03765550 }, "location_type" : "ROOFTOP", "viewport" : { "northeast" : { "lat" : 38.90006388029150, "lng" : -77.03630651970849 }, "southwest" : { "lat" : 38.89736591970851, "lng" : -77.03900448029150 } } }, "partial_match" : true, "types" : [ "street_address" ] } ], "status" : "OK" } )
Really I would like to use the data to create a split map, a normal one with a marker and a split view showing the streetview. Any suggestions?
Upvotes: 2
Views: 1827
Reputation: 413
Really, the answer is forget Zend for this. What a waste of time. So much simpler to do:
$urlencodedAddress = urlencode('1600 Pennsylvania Avenue, N.W. Washington, DC 20500');
$details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=" . $urlencodedAddress . "&sensor=false";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$geoloc = json_decode(curl_exec($ch), true);
var_dump($geoloc['results'][0]['geometry']['location']['lat']);
var_dump($geoloc['results'][0]['geometry']['location']['lng']);
cUrl is my best friend.
Upvotes: 0
Reputation: 4932
You could do this
// get json object
json_decode($response->getBody());
References. http://framework.zend.com/manual/en/zend.http.response.html
Upvotes: 2