About | Contact | Register | Advertise | FAQ
Spatial Newsletters | Twitter |
HomeNewsArticlesDataGIS JobsEDUCommunityLBSSTOREPhotosEVENTSDIRECTORYBLOGIMAGING
Software | Spotlights on Geospatial Data | GIS Education / Events | Hardware | Mobile | Web Services | Mashup Zone  
advertisement

GISuser Newsletter

GISuser Newsletter
See Recent edition
See All our pubs!

newsletter
Subscribe HERE

Twitter Button from twitbuttons.com
GISuser Sponsor


Featured GIS Jobs

Experienced GIS Analysts

Use your years of experience to envision, design, and develop the next generation of ArcGIS products. Join ESRI, where your individual contributions will have an impact on new software functionality. Apply now or search other opportunities.

GIS Job Opportunities

GIS Jobs
Loads of GIS Jobs!

Applications Analyst (Spatial Analyst)
Sales Associate
Software Architect
ArcGIS Desktop Senior Product Engineer
GIS Application Developer
Business Development Manager
Laser-Survey Lead
GIS Specialist
Sr Consultant
GIS Analyst
Geo Tech Webinar

Planning an event? Feature your webinar here
webinar
Register for a Webinar now!

GISuser Videos


More Videos HERE
Want your Video placed here? Contact us!
Recent Site Additions

GISuser Sponsor

GISuser Sponsor


GISuser 2.0

anygeo blog  gisuser flickr jaiku ovi
qik twitter youtube linkedIn
platial gisuser diggs mosh widsets

gisuser facebook page

facebook group
gisuser flickr
linkedIn
twitter
youtube
gisuser blip.tv
GISuser RSS feed

Get Listed!

Get Listed in the GISuser Industry Directory
social media
NEW - list your GIS/Geo social micro blog, twitter, facebook group etc... post your Resume HERE!

 

Home arrow Articles arrow Web Services arrow A Look at the Geocoding Functionality Build Into Google Maps API V2     

A Look at the Geocoding Functionality Build Into Google Maps API V2 PDF Print E-mail
Written by Eric Pimpler   
Tuesday, 27 June 2006
When the Google Maps API was released in early 2005, one of the most notable omissions was the ability to geocode addresses.  This posed more of an inconvenience that anything else as there are many geocoding API’s available from various sources, some of which are free to use.  Earlier this month that all changed as Google added geocoding functionality to it’s Maps API... read on about it in this fine contribution.

When the Google Maps API was released in early 2005, one of the notable omissions was the ability to geocode addresses.  This posed more of an inconvenience that anything else as there are many geocoding API’s available from various sources, some of which are free to use.  In addition, clever application developers quickly found a Google Maps hack that would simulate geocoding functionality through Google Maps.  However, the lack of true geocoding functionality built into the API was a bit of hindrance.  Earlier this month that all changed as Google added geocoding functionality to it’s Maps API in the form of a GClientGeocoder object which allows you to submit addresses for geocoding via JavaScript.  This functionality can also be accessed via HTTP requests directly from a client browser.  Some nice features of the geocoding functionality include:

- No need to break up the address into street components such as street name, city, country.  The address can be submitted as a single string.
- No need to worry about capitalization or punctuation
- Geocoder returns a nicely formatted version of the address you sent
- Geocoder returns the address broken up into components like street, country, province, prefecture, postal code, etc.
- Simpler version that returns a GLatLng
- Built-in cache to make the user experience faster response times on commonly used addresses
- Street level geocoding for the U.S., Canada, France, Germany, Italy, Spain, and Japan

At this time you are limited to 50,000 geocode requests per day per API key.  According to Google if you have a fairly stable database of addresses (e.g. a list of properties for sale), it is recommended that you geocode them once using the HTTP request method and cache the coordinates in your own database. This means your site will be faster for your users and also uses up less of your daily quota of geocode requests. 

GClientGeocoder
Let’s focus on the functionality provided by the GClientGeocoder object. 

An instance of GClientGeocoder can be created with the following line of code:

This instance of a geocoder talks directly to Google servers to fulfill geocoding requests.  An optional cache parameter allows you to specify a custom client-side cache of known addresses.  GClientGeocoder has two methods that can be used to send an address to Google for geocoding: getLatLng( ) and getLocations( ).

The getLatLng( ) method sends a request to the Google servers to geocode the specified address.  If the address is successfully located, the user-specified callback function is invoked with a GLatLng point. Otherwise, the callback function is given a null point. In the case of an ambiguous address, only the point for the best match is passed to the callback function.  Take a look at the code example below for more information on how to call getlatLng( ).  In this example, we geocode an address, add a marker at that point, and open an info window displaying the address.

The getLocations( ) method also sends a request to Google to geocode a specified address.  However, getLocations( ) differs in that it returns a JSON object containing a status code and one or more Placemark objects.  The status code is a response indicating whether the geocode request was successful or not.  Here is a full listing of the status codes obtained from the Google documentation:

In addition to the status code, one or more Placemark objects are returned.  Multiple Placemark objects are returned in the event that the geocoder finds more than one match.  Each Placemark object is composed of an address (nicely formatted and capitalized), AddressDetails, and a Point representing the location of the geocoded address.  For an example of a typical JSON object returned by the getLocations( ) method as well as a code example please see the Google documentation.
Caching Geocodes with GGeocodeCache
Performance of the geocoder can be improved through the use of the caching functionality built into GClientGeocoder.  This cache stores geocoded responses so that if the same address is geocoded again, the response will be returned from the cache rather than the Google geocoder.  This improves the performance of your application and lessens the number of requests sent to the geocoding service.  By default, caching is enabled, but can be turned off by passing a null value to the setCache( ) method on GClientGeocoder.  Caching is controlled through the GGeocodeCache class.  A new instance of GGeocodeCache is created through the GGeocodeCache( ) constructor which immediately call the reset( ) method to empty the cache.  Addresses can then be placed into the cache with the put( address,reply) method which stores the given reply under the given address.  Addresses can be retrieved from the cache through the get(address) method which returns the reply stored under the given address.  As we mentioned, the reset( ) method purges all addresses from the current cache.

One of the useful aspects of caching functionality is the ability to pre-build a cache to account for commonly used addresses in an application.  For example, if you have an application that displays common tourist attractions you would want to pre-build a client cache containing the geocoded address for each of the attractions.  This would remove the need to continually query the Google geocoder for the point of interest.
HTTP Geocoding Requests
In addition to the GClientGeocoder object you can also access the Maps API geocoder functionality through HTTP requests.  Combined with the XmlHttpRequest AJAX object, this gives you the ability to send geocode requests through server-side scripting.  A request should be sent to http://maps.google.com/maps/geo? with the following parameters:
- q - The address that you want to geocode
- key – Your Google Maps API key
- output – The format option (xml, kml, json)

For example:

http://maps.google.com/maps/geo?q=21734+Longwood,+San+Antonio+TX&output=xml&key=ABQIAAAA7_kD1t_m22HBF9feCaDPZxQZuc26M5nLyzIhAY0gIOH-LGKPdxQ6r3IzloZck1JnK6eAB02QGYg4Tg
In this case, we have specified a return type of “xml” which returns an XML output.  Open a web browser and paste the code above into the address bar and hit the “Enter” key to see the XML output returned by an HTTP request to the geocoder.  It should look something like what you see in the figure below.

google maps geocoder

Conclusion

According to Google, geocoding functionality was the most requested feature by developers.  This should come as no surprise since most applications built with the Google Maps API rely on placing points of interest on a map.  The recent update of the API to include geocoding functionality is a big step forward in the evolution of this already popular web mapping toolkit. 

Author Information

Mr. Pimpler is the owner of Geospatial Training Services, LLC, a provider of virtual and instructor led GIS training opportunities and the author of its popular virtual training course “Google Maps For Your Apps!” and the new PDF book “Google Maps API: The New World of Web Mapping”.  For more information on the Google Maps API or any other training opportunity provided by GeoSpatial Training Services, please visit our website at http://www.geospatialtraining.com

Looking for more gmaps tutorials? See Also:

  •  

    Bookmark and Share

    Follow GISuser Editor on Twitter!
    Digg!
    Browse The GISuser Industry Directory Categories
    Recent Directory Listings
    1. SPACEYES
        Category: GIS and Geospatial Software
        Created: Jul 1, 2009
    2. Maperture
        Category: Blogs
        Created: Jul 1, 2009
    3. NASA Warehouse...
        Category: GIS Data Providers
        Created: Jul 1, 2009
    4. US Fish Finder
        Category: Geo Social Network Listings (Web 2.0)
        Created: Jul 1, 2009
    5. OnlineGlobeGrid...
        Category: Twitter Tools and Add-ons
        Created: Jun 29, 2009
    Show more...
    GISuser Feature Articles

    GISuser Spotlight... Twitter clients for the Google G1 and Android mobile smart phones - I’m currently using the G1 as my main/only mobile device - it’s a perfect time for such a challenge because I’m also traveling and away from the office so there are always hiccups and glitches that can occur under such circumstances - a perfect time for a test!

    GISuser Social Spotlight... Setting up Corporate Twitter messaging or a Team Twitter - Twitter has many uses and is valuable to many users in many different ways. Once great use of Twitter is to use it for quick, convenient messaging for a team or corporate use. Imagine a team of developers spread out all over the country or perhaps a baseball team that needs to get notices about a rain-out or change in game time etc… consider a team Twitter account. See also, 10 Things A Company Should Consider when starting their Twitter social media presence

    GeoCortex Essentials, insights from the Latitude Geographics GeoCortex User Conference
    - During the last week of April in Victoria, BC, Canada, Latitude Geographics hosted a number of users and business partners at their annual GeoCortex User conference, an educational events designed to inform, educate, and stimulate users of the company's web-based mapping solutions.

    The 2009 NAVTEQ LBS Challenge a look at the semi finalists, the Winning apps, and the LBSzone picks! At the CTIA Wireless event  in Las Vegas, NAVTEQ held the award ceremonies for their 6th LBS Challenge, a competition designed to stimulate interest in location services and encourage developers to create innovative location-aware applications. We look at the state of LBS, the TOP apps, the winners, and our own top picks!

    GISuser Spotlight... 12 Great Social Media Tools for the Technology Event Planners - For an event organizer to truly embrace social media and make it useful for conference attendees and non-attendees, every event should at the very least consider these 12 useful tips provided here...

    GISuser Spotlight on Data... the 2009 State GIS Spatial Data Clearinghouse Directory -  Enter our 2009 State GIS Data Clearinghouse Directory - if you have a pointer to a better State resource than listed here please share with us so we can update the directory.

    Adding geo location to your facebook via fire eagle friends on fire app - I stumbled onto an update from the Yahoo! Fire Eagle project this morning that enables facebook users to integrate more geo location functionality into their account courtesy of the friends on fire applet.

    Connecting with facebook and Twitter from the map - IRL Connects users via Google maps - Enter IRL Connect, the latest social networking map mashup that just might make some HUGE noise.  Read on for details of this Beta test in Geo Social networking.

    Economic Stimulus Project areas that may create GIS/Geo Tech Opportunities - Like many of you, we haven't really had time to go through the entire 1,071 page Detailed List of Spending - you can view and download the entire document at ProRepublica. We did take a little time, however, to go through this fine summary.

    GISuser Spotlight... Tip - GIS Companies and Geo Twitters To Add To Your Social Bookmarks - There's lots of cool things about Twitter including a TON of third-party add-ons but what makes it very useful is the people!

    feature articlesSee more GISuser Features HERE / See GISuser Spotlights Here 

    Featured Events
    • ESRI Business GIS Summit, July 12-15, 2009 · San Diego, CA - This combination provides an unprecedented opportunity to learn how GIS addresses today's business challenges. If you're interested in business GIS as a manager, executive, or user, there's no better event to attend.vealed.
    • ESRI International User Conference, July 13-17, 2009 · San Diego, CA - ESRI customers across the globe are invited to register to attend the world's largest gathering of GIS professionals.
    • Webinar: Google Earth For Your Government Agency - Join Google and DLT an informative webinar on Tuesday, June 30th from 2-3 ET to learn more about how the Google Earth Enterprise solution is helping government agencies to collaborate, and take faster, more informed action.

    Suggested GISuser Reading
    Google Geospatial Search
    Google
     

     

    or... try our CUSTOM GISuser Google Search!

    Contribute to the GISuser Search (by Google)

    Today's Top Geo News
    LBSzone linkedin grouplbszone on facebooklbszone twitter
    Featured Contest

    ESRI 2009 LEAPIN' LIZARD PHOTO CONTEST

    Is your LizardTech Lizard star material? SHOW US and you could win a new GPS system. Simply snap a creative photo of your favorite, authentic LizardTech Collectable Lizard and see how it measures up. Photos will be featured on the official LizardTech Flickr page and voted on by viewers everywhere. Submit yours today and win!

    Sponsor

    GIS Data Nodes

    State GIS Clearinghouse Portals
    State GIS Spatial Data Clearinghouse Directory



    RSS and Feeds


    feedburner
    add to google reader




    technocrati
    Add to my Widsets
    GISuser on your mobile!

    Feedblitz updates via email, Tweet, or IM
    Software

    software reviews
    Geo Technology Software

    GISuser RSS Feed
    GISuser Site Sponsor


    Most Popular
    GISuser HOT Spots!

    Google Mashup Zone
    GISuser WebMaps
    Free Data Articles
    Spotlights & Tips
    GISuser Resumes
    Data Links
    10 Cool Things
    The LBS Zone!

    GISuser Sponsor


    Partner Sites

    machinecontrolonline 

    symbianone

    lbszone.com

    symbianone

    Affiliations


    asprs

    Directory
    Tyler Plain 
    Category: Job Seekers and Resumes





    Spatial Media, LLC ©2003 - 2008 All rights reserved / Privacy Statement