NAME

Smart - Google Maps Api HTTP geocoder

SYNOPSIS

use Google::GeoCoder::Smart;
 
$geo = Google::GeoCoder::Smart->new();

my ($resultnum, @results) = $geo->geocode("address" => *your address here*);

foreach $result(@results) {

my (%params) = $geo->parse($result);

$lat = $params{'lat'};

$lon = $params{'lon'};

};

DESCRIPTION

This module provides a simple and "Smart" interface to the Google Maps geocoding API.

It is compatible with the google maps http geocoder v3.

It is based on the current format of the xml returned by the API. If Google changes their format,

this module might stop working. The only dependency that this module has is the LWP::Simple module,

and its sub-dependencies. I wanted something that was adaptable and would return results

automaticaly formatted for perl.

If you find any bugs, please let me know.

METHODS

new

$geo = Google::GeoCoder::Smart->new("key" => "your api key here", "host" => "host here");

the new function normally is called with no parameters.

however, If you would like to, you can pass it your Google Maps api key and a host name.

the api key parameter is useful for the api premium service.

the host paramater is only necessary if you use a different google host than google.com,

such as google.com.eu or something like that.

geocode

my ($num, @results) = $geo->geocode(

"address" => "address *or street number and name* here", 

"city" => "city here", 

"state" => "state here", 

"zip" => "zipcode here"

);

This function brings back the number of results found for the address and

the results in an array. This is the case because Google will sometimes return

many different results for one address.

The geocode method will work if you pass the whole address as the "address" tag.

However, it also supports breaking it down into parts.

Once I implement a validation function, breaking it down into parts will be the

best thing to do if you wish to validate the results brought back.

parse

%params = $geo->parse($result);

parse takes any result text passed to it and parses it out into the corresponding values.

It is how you get the lat and lon values for the result.

It will also bring back several other parameters that might be of interest to some.

it returns:

	lat             #the lattitude of the result

	lon             #the longitude of the result

	formattedaddr   #the formatted address of the result

	streetnum       #the street number of the result

	streets         #the streets returned. 

              		#it returns an array because sometimes 

               		#google brings back more than one street name.

	cities          #the cities returned. 

			#its an array because sometimes google

			#sometimes brings back more than one city


	state		#the state returned by google for the result *administrative_area_level_1 for those outside the US

	zip		#zip code of the result

	county		#if applicable, returns the administrative_area_level_2 *which is the county in the US*

	type		#brings back the match type *see the google maps api documentation* 

			#common results are street_address or postal_code

	match		#brings back the match type. it is set to yes if the result is a partial match, 

			#and null if it is a full match

AUTHOR

TTG, ttg@cpan.org

COPYRIGHT AND LICENSE

Copyright (C) 2010 by TTG

This library is free software; you can redistribute it and/or modify

it under the same terms as Perl itself, either Perl version 5.10.0 or,

at your option, any later version of Perl 5 you may have available.