Click here to Skip to main content
Click here to Skip to main content

Tagged as

Consuming Google Maps API Rest Services in .NET

, 23 Jul 2010 CPOL
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

Comments and Discussions

GeneralThis isn't really a tip/trick. Why don't you flesh it out a... PinmemberTheyCallMeMrJames23-Jul-10 5:47 

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.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150331.1 | Last Updated 23 Jul 2010
Article Copyright 2010 by Pandey Vinay
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid