I created this utility and it has been working for me for a while. Of course, if Google maps changes its API, it must be changed.
<?php // Queries google maps for the address components function utl_GetAddressComponents( $location ) { $components = file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.urlencode($location).'&sensor=false'); $output = json_decode($components); return $output->results[0]; } ?>
Here is the test file that I used to run from the command line:
tst_MatchingAddresses.php: <?php require_once( "utl_GetAddressComponents.php" ); $addr1 = $argv[1]; $addr2 = $argv[2]; $gmapsResult1 = utl_GetAddressComponents( $addr1 ); $gmapsResult2 = utl_GetAddressComponents( $addr2 ); $gmapsAddr1 = $gmapsResult1->formatted_address; $gmapsAddr2 = $gmapsResult2->formatted_address; print("Gmap1: ".$gmapsAddr1." ----- argv[1]: ".$argv[1]."\n"); print("Gmap2: ".$gmapsAddr2." ----- argv[2]: ".$argv[2]."\n"); if ( strcmp($gmapsAddr1,$gmapsAddr2) ) { print("==> Addresses match!\n"); } else { print("==> Addresses DO NOT MATCH!\n"); } ?>
Here is an example command line:
php tst_MatchingAddresses.php "1600 Pennsylvania Ave, Washington DC" "1600 Pennsylvania Avenue, 20500"
Output Example:
Gmap1: 1600 Pennsylvania Avenue Northwest, President Park, Washington, DC 20500, USA ----- argv[1]: 1600 Pennsylvania Ave, Washington DC Gmap2: 1600 Pennsylvania Avenue Northwest, President Park, Washington, DC 20500, USA ----- argv[2]: 1600 Pennsylvania Avenue, 20500 ==> Addresses match!
Note. You can enter an argument into get_contents_file, replace urlencode, etc. address directly in the browser and display json results.
source share