Click here to Skip to main content
Licence 
First Posted 23 Jul 2007
Views 38,229
Downloads 345
Bookmarked 50 times

How Google Map Works (part2): The geocoder

By Pascal Buirey | 27 Jul 2007
Ask GoogleMap for coordinates
1 vote, 11.1%
1

2

3
1 vote, 11.1%
4
7 votes, 77.8%
5
4.68/5 - 9 votes
μ 4.68, σa 2.33 [?]

Introduction

After having found how to get the image corresponding to geographic coordinates (view article), I wanted to look at another interesting point about Google maps: the geocoder. A geocoder is a service that allows you to find the longitude and latitude corresponding to a place name. I know the name of my street and city, but to get the image I need the geographic coordinates. This article explains how to ask Mr Google, who knows all this.

The request

To ask Mr Google for coordinates, you need to ask in the right way and tell him how to answer. To do this, you will have to create a web request with the URL:

http://maps.google.com/maps?output=kml&q=my street name

http://maps.google.com/maps will throw your request to the geocoder service. The output=kml parameter will tell Mr Google to answer in an easily comprehended way and the q=my_street_name parameter will indicate to Mr Google the point for which you need some information.

The answer(s)

I have found two possible answers: If there is no ambiguity about the place name, Google will send you the coordinates. If Google needs more precision, it will send back a list of possible place names. Then you will have to make another request with the right choice in the list. In the case of final response, the answer is an XML file that looks like this :

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Placemark>
    <name>New York, NY</name>
    <address>New York, NY</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
    <Point>
        <coordinates>-74.007130,40.714490,0</coordinates>
    </Point>
    <LookAt>
        <longitude>-74.007130</longitude>
        <latitude>40.714490</latitude>
        <range>64586.917969</range>
    </LookAt>
</Placemark>
</kml> 

However, if Google needs more precision, the answer will look like this:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Folder>
<name>Did you mean:</name>
<open></open>
<Placemark>
    <name>Paris, Lamar, Texas, United States</name>
    <address>Paris, Lamar, Texas, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Henry, Tennessee, United States</name>
    <address>Paris, Henry, Tennessee, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Edgar, Illinois, United States</name>
    <address>Paris, Edgar, Illinois, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Bourbon, Kentucky, United States</name>
    <address>Paris, Bourbon, Kentucky, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Logan, Arkansas, United States</name>
    <address>Paris, Logan, Arkansas, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Monroe, Missouri, United States</name>
    <address>Paris, Monroe, Missouri, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Mecosta, Michigan, United States</name>
    <address>Paris, Mecosta, Michigan, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Bear Lake, Idaho, United States</name>
    <address>Paris, Bear Lake, Idaho, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Stark, Ohio, United States</name>
    <address>Paris, Stark, Ohio, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
<Placemark>
    <name>Paris, Lafayette, Mississippi, United States</name>
    <address>Paris, Lafayette, Mississippi, United States</address>
    <styleUrl>root://styleMaps#default+nicon=0x304+hicon=0x314</styleUrl>
</Placemark>
</Folder>
</kml> 

In this case, take the address parameter and send a new request with this address. The provided Sample is a .NET control written in C#.

History

  • 24th July, 2007 -- Original version posted
  • 27th July, 2007 -- Article edited and moved to the main CodeProject.com article base

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Pascal Buirey

Web Developer

France France

Member


Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page   
  Refresh
GeneralThank You... PinmemberVasudeva Kiran21:29 26 Aug '08  
GeneralGoogle GeoCode PinmemberMy name dammit !21:21 31 Jul '07  
GeneralGoogle GeoCode PinmemberMy name dammit !21:20 31 Jul '07  
QuestionAPI Example too? Pinmemberdcrane12:42 30 Jul '07  
AnswerRe: API Example too? PinmemberPascal Buirey21:42 30 Jul '07  
GeneralRe: API Example too? [modified] Pinmemberdcrane22:01 30 Jul '07  

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Mobile
Web01 | 2.5.120209.1 | Last Updated 27 Jul 2007
Article Copyright 2007 by Pascal Buirey
Everything else Copyright © CodeProject, 1999-2012
Terms of Use
Layout: fixed | fluid