paste
<?php

// Clean the address just in case
function cleanAddress($address){
return str_replace("'", '', utf8_encode(str_replace("\n", '', $address)));
}

// Make a nice search string
$searchString = rawurlencode(cleanAddress($myAddress));

// The location of the google maps geocoder
$address = "http://maps.google.com/maps/geo?q=".$searchString."&output=xml&key=$myGoogleKey";

// Get the xml code
$page = file_get_contents($address);

if($page){

list($junk, $page) = split('<coordinates>', $page);

list($page, $junk) = split('</coordinates>', $page);

list($longitude, $latitude, $altitude) = split(',', $page);

echo 'lon: '.$longitude.' lat: '.$latitude;

}

?>
  1. <?php
  2.  
  3. // Clean the address just in case
  4. function cleanAddress($address){
  5.         return str_replace("'", '', utf8_encode(str_replace("\n", '', $address)));
  6. }
  7.  
  8. // Make a nice search string
  9. $searchString = rawurlencode(cleanAddress($myAddress));
  10.  
  11. // The location of the google maps geocoder
  12. $address = "http://maps.google.com/maps/geo?q=".$searchString."&output=xml&key=$myGoogleKey";
  13.  
  14. // Get the xml code
  15. $page = file_get_contents($address);
  16.  
  17. if($page){
  18.  
  19.         list($junk, $page) = split('<coordinates>', $page);
  20.  
  21.         list($page, $junk) = split('</coordinates>', $page);
  22.  
  23.         list($longitude, $latitude, $altitude) = split(',', $page);
  24.        
  25.         echo 'lon: '.$longitude.' lat: '.$latitude;
  26.  
  27. }
  28.  
  29. ?>