Click here to Skip to main content
13,290,735 members (79,090 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 23 Jul 2010

Consuming Google Maps API Rest Services in .NET

, 23 Jul 2010
Rate this:
Please Sign up or sign in to vote.
This is a direction to use Google Maps API Rest Services instead of using it from JavaScript.


GooglMapsAPI is very easy to use if you have to use it on an HTML page using JavaScript, but if you have to use GooglMapsAPI for retrieving data instead of directly displaying the page, then it becomes a bit hectic. The output is available in two forms JSON and XML. The attached code contains a class that can be used to deserialize the XML output and format it in .NET class so that we can use it the way we want.

Using the code

For using the GoogleMapsAPI, what we do is follow:

First make formatted HTTP request to the service.

string url =String.Format(
"{0}&sensor=false", "Andheri West".Replace(" ", ",")
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url );
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream outputStream = response.GetResponseStream();
StreamReader reader = new StreamReader(outputStream, Encoding.ASCII);
string output = reader.ReadToEnd();

The response is either in the form on JSON or XML so deserialise the response into a .NET class.
Once we have the response of our request, it is time to deserialize the response:
XmlSerializer serializer = new XmlSerializer(typeof(ElevationResponse));
streamForDeserialization streamForDeserialization = new StringReader(output);
XmlTextReader readerForDeserialization = new XmlTextReader(streamForDeserialization);  
ElevationResponse elevationResponse =

Use the output as you need. Since the output is not easy to understand, it is better is to find out the neccessary fields and use them instead of the object of entire response.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pandey Vinay
India India
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralThank you for the fantastic example; voting it a 5!. It save... Pin
Member 381091511-Dec-11 4:01
memberMember 381091511-Dec-11 4:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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 | Terms of Use | Mobile
Web01 | 2.8.171207.1 | Last Updated 23 Jul 2010
Article Copyright 2010 by Pandey Vinay
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid