How to use Google Static Map API in Windows Mobile

I have noticed so many times over the Microsoft smart device forum lots of time developer ask this question to how to get Google static map according to latitude and longitude. So I have decided to write a very simple article with an example to solve this problem using some static geo data. Apart from that this article will cover, how to use Google Static Map API.

In this article I have used some static geo data like (latitude and longitude) to get the Google static map using google static map api. Here I am going to explain how to use google map api to get the google static map and how to pin location on the static map in widows mobile application.

Here we go.

Let us have a glace of Google static map documentation here

In this application I have created a GoogleMapAPIs class for format the Google Static Map API. This class contents two static methods for google map API. In these methods I have formed api for the generic purpose for passing parameters google map url.

A Google Static Maps API URL must be of the following form:

http://maps.google.com/maps/api/staticmap?parameters

To get the static map API

http://maps.google.com/maps/api/staticmap?center=25.1950004243,75.8362304687&zoom=12&size=240x320&sensor=false

In the above url, some Map Parameters.

center: this parameter consider comma-separated {latitude,longitude} like this 25.1950004243,75.8362304687

zoom: this parameter we can pass the zoom level 0-21

size: this parameter we need to pass image size in height and width here I passed 240×320 in string format like width x height.

sensor: if the mobile application is using using a “sensor” then we have to pass true otherwise false

http://maps.google.com/maps/api/staticmap?size=240x290&maptype=roadmap&markers=size:mid|color:red|Delhi&sensor=false

In the above url, some Map Parameters.

size: this parameter we need to pass image size in height and width here I passed 240×320 in string format like width x height.

maptype:it isspecifies a standard type of map like roadmap, satellite, terrain, hybrid

markers:it is used to show pin on the map which is define one or more markers to attach to the image at specified locations.

sensor: if the mobile application is using a “sensor” then we have to pass true otherwise false

Let us take an example how to call Google map api in Windows mobile application.

In the windows mobile project I have added a class WebAccessUtility.cs this class have static method to call the google map api and download the image in Jpeg format.

public static bool GetStaticGoogleMap()
{
bool isSuccess = false;
string WebUrl = string.Empty;
try
{
if (isRoadMap)
{
WebUrl = GoogleMapAPIs.GetGoogleRoadMapAPIs();
}
else
{
WebUrl = GoogleMapAPIs.GetGoogleMapAPIs();
}

HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(WebUrl);
httpRequest.Timeout = 15000;
httpRequest.ReadWriteTimeout = 20000;

using (HttpWebResponse httpResponse = (HttpWebResponse)httpRequest.GetResponse())
{
using (Stream imageStream = httpResponse.GetResponseStream())
{
using (Bitmap buddyIcon = new Bitmap(imageStream))
{
buddyIcon.Save(strPath + strFileName, System.Drawing.Imaging.ImageFormat.Jpeg);
isSuccess = true;
};
};
};

}
catch (WebException wx)
{
switch (wx.Status)
{
case WebExceptionStatus.ConnectFailure:
throw ex;
break;
}
}
catch (Exception ex)
{
throw ex;
}
return isSuccess;
}

This method will take care to call the API type if user call the map type is road or normal. See below screen there is a menu you can choose location first then select the map type.

Now choose the Get Map from the Menu then it will display map accordingly.

To get the road type of map then chooses the Get Road Map from the Menu.

Download Source Code here

Note: do not forget to cradle your emulator or device for the internet connectivity.

Thank you 🙂

Advertisements

About Pavan Pareta

My name is Pavan Pareta, I enjoy computers and general technology. I am more interested in the areas of Computer Security, Programming and developing innovative s/w for Windows Mobile and Windows Phone 7. I like MS Technology and support open-source software, because I believe it plays a major role in knowledge sharing and exchange of ideas, which effectively leads to better software. Additionally, I am a follower of the KISS (Keep It Simple Stupid) philosophy. I Love C#.NET and recently I am fall in love with Silverlight :) Introduce to my machine My main workstation is a Intel Pentium Core Duo and my primary operating system is Windows 7.
This entry was posted in Windows Mobile. Bookmark the permalink.

3 Responses to How to use Google Static Map API in Windows Mobile

  1. isuru says:

    Can you please tell me what is the needed compact framework and is this supports to the windows mobile 5.0 to run this examplethank you!

  2. AmitDiwan says:

    hi sir,Can OpenStreetView be implemented in silverligh(dotnet)…I implemented BING MAPS in silverlight.But having no idea about OpenStreetView.?Any help?

  3. Hai Dude,I'm Raghavendra Rao, Software Developer working in NCPL Technologies in Visakhapatnam. I've been working here from past 2years. Did many of the projects in both windows and some on web. Here i've got a new problem in one of my project that has been assigned to me.On querying about the solution for it, i've came across your blog which felt very interesting and useful to me.My problem is, I've to develop a GPS application in Windows Mobile. The reqts are as follows:This entire application should be combined and should run in a windows mobile application.Current Progress of my proj:I've worked on the problem of my project and found out a solution. I've used Static Google map api's in order to find out the shortest path between two locations. Its working fine but a problem again arised. The points that i've selected are being displaced in the map but they are joined with a single straight line, but not navigating through the streets and all those areas. I've tried various methods to generate a path rather than a straight line, but failed. Hence I request you to provide a quick and a useful solution for this prob

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s