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

See Recent edition

GIS user free newsletter 

subscribe GISuser



follow GISuser on Twitter
TOP Stops!

webinar

GISuser Sponsor


iPhone Geo Stuff!

Visit the iPhone Zone

Featured Event

 where2.0
15% Discount: whr10giu

GIS Job Opportunities
 

Loads of GIS Jobs!

.Net Developer
Project Manager-Application Development
Tenure-Track Spatial Analysis
GeoSpatial Sales and Channel Partner Coordinator
High Level Consultant for Haiti Data
Tenure-Track Assistant Professor in Applied Remote Sensing
GIS Technician
Geospatial/GIS Policy Lead
State GIO
Support Analyst - Programming
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
gisuser flickr
linkedIn
twitter
youtube
gisuser blip.tv

Directory
Nulaz  
Category: Social Networking and Social Location Services


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   
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:

  •  

    deliciousrssnewsletterlinkedinfacebooktwitter

    Bookmark and Share

    Follow GISuser on Twitter
    @GISuser!
    blog comments powered by Disqus
    Digg!
    GISuser Feature Articles

    Top iPhone related GIS and Geo Tech news stories from 2009 - At the end of the year its always interesting for us to look at some of the stats and results to identify trends and more important, to see what our readers think is hot! In the "news" category it seems that iPhone related geo tech items were extremely popular.

    10 Awesome GIS and Mapping apps for the iPhone - I recall last year at the ESRI UC when an iPhone was on stage showing a prototype app (think ArcPad on iPhone). It was then that I realized the iPhone platform is going to be BIG in mapping and there's a ton of opportunity for developers.

    Nokia Booklet 3G, unboxing video and image gallery... Those of you in the USA who pop in to BestBuy occasionally, you may have seen a stand showing off the Nokia Booklet 3G. A sleek, 3G enabled, SIM slot (AT&T) sporting netbook. 

    Interesting Tweeple - 10 Geo Technology & Geo-Social Women of Twitter - given the growing love for geospatial and location-aware technologies, I’ve decided to hype 10 women that I feel make a significant contribution to the Geo-Twittersphere. If you’d like to add 10 knowledgeable and useful Twitter contacts to your Geo following list I highly suggest the following: (in no particular order)

    10 Geo Social Location-Aware Apps Making Waves... With Twitter's opening of their location API to developers there's going to be a ton of third party apps that will enable Twitter users to share location-aware information via their Twitter accounts.

    Signs that indicate you may be a GeoGeek (aka. GeoNerd) and some suggested Geo blogs - Chances are good that if you are a Geo Geek then you already know it and likely refer to yourself as one. However, there’s many of you out there that may be on the fence and wondering… “am I a Geo Geek?" Read on for a comprehensive list of signs you might be a GeoGeek followed up by some suggested Geoblog reading.

    Real-time GPS Mapping and GIS Solution Aids Efficient Disaster Management  - Saturday, February 7, 2009 will forever be known as Black Saturday in the State of Victoria, Australia. In the midst of a 10-year drought, a record breaking heat wave descended upon the state, with temperatures exceeding 45 degrees C (110-120 deg F), breaking all-time record highs in some cities - Victoria Police Use Trimble Juno SC Handhelds to Speed Assessment of Damage Caused by Bush Fires.

    Data Spotlight - USGS and a new generation of Topo Maps - A primer on US Topo - Downloading “free” USGS topos from around the web?? Are you getting the new, enhanced USGS topos - US Topo?

    The world's largest signpost maps out the UK's Good Things Last week in London, some 10 Mobile bloggers and mobile technology enthusiasts were in London to help Nokia promote the launch of Ovi Maps Good Things campaign. A promotion designed to encourage users of the Nokia N97 and new N97 mini to add Good Things to Ovi maps... check out more details and add your good things at http://maps.ovi.com/goodthings/ - see more on the sign post here

    RunningMap Trackometer, iPhone app for runners and outdoor enthusiasts - I just heard about another cool location-aware iPhone app ideally geared towards runners and outdoor enthusiasts (and Geographers!) RunningMap (from Canadian company Spin Technologies).

    10 Ways Your Tech Business Can Take Advantage of Twitter - Many companies and individuals are still asking themselves how can I use Twitter in my business? The following is a small sampling of some of the ways that your technology business can use Twitter to your advantage.

    City of Vancouver BC, Canada Opens Access to Data - The City of Vancouver has launched its OpenData web site providing simple discovery and access to GIS data.

    EPA Economic Stimulus and Recovery Efforts Map - View spending for each State broken down by $$ totalts obligated and spent. Click additional info for more detailed budget info.

    Openness via Data.gov - Access A Wealth of Geospatial Data and a Cool ESRI SHP file Viewing Tool - Data.gov increases the ability of the public to easily find, download, and use datasets that are generated and typically held by the Federal Government.

    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

    feature articlesSee more GISuser Features HERE / See GISuser Spotlights Here 

    Recent Directory Listings
    1. DoubleDutch Check-in...
        Category: Social Networking and Social Location Services
        Created: Mar 15, 2010
    2. It's All About Data -...
        Category: Blogs
        Created: Mar 12, 2010
    3. GeoSearch, Inc.
        Category: Careers and Employment
        Created: Mar 11, 2010
    4. Tweetshare
        Category: Twitter Tools and Add-ons
        Created: Mar 11, 2010
    5. Tweetsii (for iPhone)
        Category: Twitter Tools and Add-ons
        Created: Mar 11, 2010
    Show more...
    Featured Events
    • Free Webinars and online training from LizardTech - Training dates include Feb 2, 16, 23
    • 2010 ESRI Federal User Conference February 17-19, 2010, Washington D.C. Walter E. Washington Convention Center - The FedUC is the largest geospatial conference for federal agencies. Connect with other leaders, decision makers, and GIS professionals.
    • The International LiDAR Mapping Forum 2010 - Tenth Anniversary Event! ILMF 2010 will be held from March 3 - 5, 2010 at the Hyatt Regency in Denver at Colorado Convention Center.
    • The NAVTEQ 2010 Global LBS Challenge Awards Ceremony will be held during Ignite at O'Reilly Where 2.0. Be among the first to hear as NAVTEQ announces the winners for the North America region. Participants will be competing for a global prize pool of $10 million and growing by showcasing pre-commercial location-enabled apps using NAVTEQ map data & products. March 30, 2010, during Ignite Where, 7:30pm - 9:00pm, at the Marriott San Jose, CA
    • WHERE2.0 2010 - Now in its sixth year, the Where 2.0 Conference is where the grassroots and leading edge developers building location-aware technology intersect with the businesses and entrepreneurs seeking out location apps, platforms, and hardware to gain a competitive edge. For 15% use Discount Code: whr10lbs
       

      List Your Event Here 

    Suggested GISuser Reading
    Google Geospatial Search
    Google
     

     

    or... try our CUSTOM GISuser Google Search!

    Contribute to the GISuser Search (by Google)

    TOP News Story
    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

    Spatial Media LLC
    A Spatial Media LLC property

    Affiliations


    asprs

    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!

     




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