Mobile Zone is brought to you in partnership with:

Den is a DZone Zone Leader and has posted 460 posts at DZone. You can read more from them at their website. View Full User Profile

Tip of the day for Windows Phone developers - the Map control is not always necessary

09.02.2011
| 6334 views |
  • submit to reddit

If you look in the Windows Phone Marketplace, you will notice that there is a plethora of applications that are using device-based location and maps. There is the Map control that facilitates the use and customization of user's surroundings, but what some developers don't know is that for some static content the Map control is overkill.

Instead, it is worth looking at the open Bing Maps API that allows the developer to access location tiles in different formats and sizes, as long as the longitude and the latitude of a searched point are known.

For example, here is a service request URL that will return a location tile:

http://tiles.virtualearth.net/api/GetMap.ashx?c=39.213413,-98.699930&w=800&h=800&b=r,stl.h,device.mobile,mkt.en-US&z=15&logo=no&da=n

Notice how I am passing the latitude and the longitude via the c parameter. w and h parameters determine the width and height of the returned image. b is the appearance descriptor. In this case, there is a device.mobile option that will increase the frequency of different location indicators (e.g. street names or highway numbers).

The z parameter is the zoom factor. This value has the range: 1 to 21 (21 being the highest). Going beyond this range will cause a Bad Request error.

But I don't want the logo on the map...

For whatever reason you might need to remove the logos from the tile (e.g. taking too much space), you can do this through the same URL parameters. To remove the Bing logo, use the logo=no pair. To remove the NAVTEQ reference, use the da=n pair. Compare the two images above to see what I am talking about.

How can I get the lat/lon values?

The coordinates used in the service request are used in the same format as the latitude and longitude returned by GeoCoordinateWatcher:

GeoCoordinateWatcher watcher;
public MainPage()
{
    InitializeComponent();

    watcher = new GeoCoordinateWatcher();
    watcher.Start();
    watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
}

void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    Debug.WriteLine(e.Position.Location.Latitude + " " + e.Position.Location.Longitude);
}

These service endpoints can be extremely useful for what Windows Phone does best - implement live tiles.