06-03-2009, 11:18 PM
|
#5 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
|
Quote:
Originally Posted by paulriedel
Very dirty but quick and works
|
Instead of doing very crude exploding, etc. you could be a little more clear when parsing out what you want.
For example, you could just use strpos to check for the status element containing "200". You could use string functions (strpos, substr, and the like) or regular expressions to get at the lat-lon coordinates.
Alternatively, depending on your needs, you could just use their CSV result format. I don't have PHP 4 to test against, but here is the idea:
PHP Code:
<?php
$address = 'Süderstrasse 77, 20097, Germany'; $endpoint = 'http://maps.google.com/maps/geo?output=csv&key=test&q='; $request = $endpoint.urlencode($address);
// Grab data using file functions $file = fopen($request, 'r'); $data = fgetcsv($file, 30); fclose($file);
// Parse CSV response $status = (int) $data[0]; $accuracy = (int) $data[1]; $latitude = (float) $data[2]; $longitude = (float) $data[3];
echo '<pre>'; var_dump($data, $status, $accuracy, $latitude, $longitude); echo '</pre>';
?>
|
|
|
|