Mobile Line Of Business

Richard Jones (MVP)

  Home  |   Contact  |   Syndication    |   Login
  202 Posts | 0 Stories | 36 Comments | 0 Trackbacks

News

Welcome to the Mobile Line Of Business Blog

Tag Cloud


Archives

Post Categories

About

I’m back developing a fair few prototype Windows Mobile applications.   I’ve just put together a small field service application that I needed to add some bells-and-whistles to.

What better for the field engineer but to have maps available.   I wanted to have my map displayed right inside of a Compact Framework form.

 

image

A really well kept secret is that you can use Virtual Earth as a tile server   to give you nice optimised for mobile map images.    Now their are licence implications for doing this, and to the letter of the law you have to have a Microsoft MapPont.Net licence.   

Any map tile can be retrieved using a very simple URL as follows

http://api.tiles.virtualearth.net/api/GetMap.ashx?b=h,device.mobile&op=0,,52.1439066666667,0.0902583333333333&c=52.1439066666667,0.0902583333333333&w=452&h=246&z=14

It is composed of the longitude and latitude (in decimal format) for the centre of your map and you can even specify and overlaid pin.   Finally you can specify the size of your map and zoom level.

So I’ve wrapped up the construction of this URL into a simple Compact Framework method.   Here it is -

public enum MapStyle
        {
            road,
            hybrid,
 
        }
        public static string GetMapUrl(decimal longitude, decimal latitude, int width, int height, int zoom,MapStyle mapstyle)
        {
            StringBuilder sburl = new StringBuilder();
            sburl.Append("http://api.tiles.virtualearth.net/api/GetMap.ashx?b=");
            switch (mapstyle)
            {
                case MapStyle.road:
                    sburl.Append("r");
                    break;
                case MapStyle.hybrid:
                    sburl.Append("h");
                    break;
                default:
                    break;
 
            }
            
            sburl.Append(",device.mobile&op=0,,");
            sburl.Append(latitude);
 
            sburl.Append(",");
            sburl.Append(longitude);
            sburl.Append("&c=");
            sburl.Append(latitude);
            sburl.Append(",");
            sburl.Append(longitude);
 
            sburl.Append("&w=");
            sburl.Append(width);
            sburl.Append("&h=");
            sburl.Append(height);
            sburl.Append("&z=");
            sburl.Append(zoom);
            return sburl.ToString();
        }

I then simply put a web-browser control on the form and navigate to the URL produced from the above method.

 

posted on Saturday, January 24, 2009 3:57 PM