Tuesday, March 6, 2012

Windows Phone - Bing Maps and Location tracking

Yesterday I set up a quick test of Bing Maps and location tracking (using GPS and/or network)  for Windows Phone. Location tracking is very similar to how it's done on Android:

  1. Get an API key ( http://www.bing.com/toolbox/bingdeveloper/)
  2. Create a GeoWatcher instance (Android equivalent: LocationManager)
  3. Add event listeners for when the position or location status has changed
  4. Start the GeoWatcher instance in it's own thread (Android equivalent:  LocationManager.requestLocationUpdates which does step #3 and #4 in one go)
  5. Receive location updates as GeoCoordinates containing latitude, longitude and optionally altitude, accuracy, speed and course. Latitude and longitude are in the range -180.0 to 180.0 as opposed to the Android micro degrees
And when it comes to the actual map it's not really any different from working with Google Maps either:

  1. Add a Map tag to your XAML and your API key as an attribute
  2. Add optional things like starting zoom level and if zoom controls should be visible or not
  3. As child tags you can add PushPins, Layers and Shapes (to plot routes and areas)
The above can be done programatically of course. I did however decide to go for full use of XAML and databinding to bind the "I'm here" pushpin location to the location I get from the GeoWatcher. Simple and very elegant.

No comments:

Post a Comment