View Single Post
Old 06-03-2009, 11:18 PM   #5 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Quote:
Originally Posted by paulriedel View Post
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($file30);
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>';

?>
Salathe is offline  
Reply With Quote