NAME

Smart - Google Maps Api HTTP geocoder

SYNOPSIS

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

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

$resultnum--;

for $num(0 .. $resultnum) {

$lat = $results[$num]{geometry}{location}{lat};

$lng = $results[$num]{geometry}{location}{lng};

};

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.

the XML parsing is based on the current format of the xml returned by the API.

If Google changes their format, it might stop working.

This module only depends on LWP::Simple and JSON.

#################################################

MAKE SURE TO READ GOOGLE's TERMS OF USE

they can be found at http://code.google.com/apis/maps/terms.html#section_10_12

#################################################

If you find any bugs, please let me know.

METHODS

new

$geo = Google::GeoCoder::Smart->new("method" => "json", "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 result format, Google Maps api key and a host name.

the default result format is json. However, if you wish to use my own homemade XML parsing,

or if you want the whole xml file for other purposes, you can specify xml in the "method" argument.

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.http://code.google.com/apis/maps/terms.html#section_10_12

geocode

my ($num, $error, @results, $returntext) = $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.

It also returns the result text for debugging purposes.

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

However, it also supports breaking it down into parts.

It will return one of the following error messages if an error is encountered

connection         #something went wrong with the download

OVER_QUERY_LIMIT   #the google query limit has been exceeded. Try again 24 hours from when you started geocoding

ZERO_RESULTS       #no results were found for the address entered

If no errors were encountered it returns the value "OK"

If you are using xml, you will have to run the parse method on each result in the array to bring back values from it.

If you use the json format, you can get the returned parameters easily through refferences.

$lat = $results[0]{geometry}{location}{lat};

$lng = $results[0]{geometry}{location}{lng};

When using the JSON method, it is helpful to know the format of the json returns of the api.

A good example can be found at http://www.google.com/maps/apis/geocode/json?address=1600+Amphitheatre+Parkway+Mountain+View,+CA+94043&sensor=false

parse

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

Parse is only useful for the xml parameter. It 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.