Hacking Google Maps and Google Earth (ExtremeTech)

(Dana P.) #1

Chapter 6: Working with Existing Address Information


The preceding script contacts the geocoder.usserver and then dumps out the information
returned. For example, with this script you can supply the address information on the com-
mand line:
$ geocoderus.pl Madison at 45th, New York, NY
$VAR1 = [
{
‘type1’ => ‘Ave’,
‘type2’ => ‘St’,
‘lat’ => ‘40.754951’,
‘street1’ => ‘Madison’,
‘suffix1’ => ‘’,
‘prefix2’ => ‘E’,
‘suffix2’ => ‘’,
‘state’ => ‘NY’,
‘zip’ => ‘10017’,
‘city’ => ‘New York’,
‘prefix1’ => ‘’,
‘long’ => ‘-73.978088’,
‘street2’ => ‘45th’
}
];

You can see from the output that the latitude and longitude are in the ‘lat’and ‘long’
keys of the returned hash. You can also see that the rest of the address information is returned
as well, including the Zip code and the full street names of the intersection of 45th Street and
Madison Avenue in New York (the location of the Roosevelt Hotel). If the returned informa-
tion has not been populated with the latitude and longitude and Zip code information, the
supplied string probably could not be understood.

The same basic principles can be used to geocode any U.S. address information. You could use
a modified format of the preceding code to update your address database or the database used
to hold specific information about map data.

The service provided by geocoder.usis free, but if you expect to use the site in a commercial
environment with large numbers of requests, you should consider signing up for an account that
enables you to bulk-purchase lookups. The money you pay goes toward supporting the service.

The geocoder.usservice is probably the most practical solution for large-volume lookups.
Although you can use it live, I’ve generally found the geocoding and interface to be more useful
when you are encoding a lot of addresses, such as when updating an existing database.

Looking Up Global Information


If you are trying to look up information outside the larger and more popular territories of the
United States and the U.K., you have a number of different options.
Free download pdf