views:

143

answers:

2

I am geocoding a large amount of user entered addresses and interested in the accuracy levels returned. My GOAL is to get the BEST POSSIBLE ACCURACY score for a given address.

I call the geocder api following way http://maps.google.com/maps/geo?q={address}&output=csv&sensor=false&key=xx

now the accuracy levels returned for same address with/without premise name

  1. q = Key Arena, 305 Harrison Street, Seattle, WA 98109 (Accuracy is 5)
  2. q = 305 Harrison Street Seattle, WA 98109 (Accuracy is 8)
  3. q = Key Arena, Seattle, WA 98109 (Accuracy is 9.)

Its obvious from the above that the google servers does not return the best accuracy when street name is appended with premise/venue.

the question is :) is there a way to pass the complete address ( with premise name / i.e case 1 ) and get the Max Accuracy. ( or how can tell the google server that the address is passed with premise/building name and street name)

( if you are thinking why not just use case 3, the answer is these are user entered addresses, they could enter "my moms's house" for premise, with accurate street address. in which case i want the accuracy to be 8 not 5)

A: 

It's pretty easy, just do an if statement to check and see what the accuracy is. If it is too low, try and goecode without your premise name. In my case below, I'm trying addr_2 and then addr_3 to account for the situations where the user entered a name on addr_1.

$addr_1 = urlencode($row["addr_line1"]);
$addr_2 = urlencode($row["addr_line2"]);
$addr_3 = urlencode($row["addr_line3"]);
$city = urlencode($row['addr_city']);
$state = urlencode($row['addr_state']);
$postal = urlencode($row['addr_postalcode']);
$country = urlencode($row['addr_country']);

$address = format_address($addr_1, $city, $state, $postal, $country);
$base_url = "http://" . MAPS_HOST . "/maps/geo?output=json&key=" . KEY;

$request_url = $base_url . "&q=" . $address;
$geocode = geocode_address($request_url);

// check geocode accuracy and try again with different data if needed
if ($geocode['accuracy'] < 6) {
      // bad geocode, try addr_2
      $address2 = format_address($addr_2, $city, $state, $postal, $country);
      $request_url2 = $base_url . "&q=" . $address2;
      $geocode = geocode_address($request_url2);

      if ($geocode['accuracy'] < 6) {
        // bad geocode, try addr_3
        $address3 = format_address($addr_3, $city, $state, $postal, $country);
        $request_url3 = $base_url . "&q=" . $address3;
        $geocode = geocode_address($request_url3);
      }
}
// process results in $geocode below

See Geocoding Addresses with PHP/MySQL for more details on what I'm doing in format_address() and geocode_address().

"large amount of user entered addresses" in the question means i have more than 3 million address estimated 85% having invalid/unrecognized location name. So, well was trying to reduce the number of calls to the geocoding service.You are right, i have no other option but to make multiple calls.
Well today when i checked the address "Key Arena, 305 Harrison Street, Seattle, WA 98109"does return the accuracy as 9. So i assume either there was some glitch with geocoding service or google changed their algo..
A: 

Well today when i checked the address "Key Arena, 305 Harrison Street, Seattle, WA 98109" does return the accuracy as 9. So i assume either there was some glitch with geocoding service or google changed their algo..