MOBILE

Introducing the Windows Phone Location Service and Mapping APIs

2/28/2011 10:50:03 AM

1. Understanding Windows Phone Location Services Architecture

A Windows Phone device can determine its current position on the surface of the earth in one of three ways. The first approach is to use the built-in GPS receiver, which uses satellites and is the most accurate, but which also consumes the most power. The second and third approaches are to use Wi-Fi and the triangulation of the cell phone towers, which are much less accurate then GPS receiver but consume less power. Fortunately, the Windows Phone Location Service automatically decides which option is best for the location of a device and presents its best guess of longitude and latitude through the Bing Maps location service. With a longitude and latitude reading in hand, an application can plot it on a Bing Maps Silverlight control map. Or you can use a street or civic address returned by the on-board location service to query the Bing Maps web service for its corresponding GPS coordinates (longitude and latitude) and plot them on a Bing Maps map.

2. Introducing the Windows Phone Location Service and Mapping APIs

In order to use the location service on a device, you need to reference the System.Device assembly and declare System.Device.Location in your code. And before you can take advantage of the location service, you must enable the location service on the phone by going to Settings => Location => turn on Location Services option. You can detect whether the phone's location service is enabled using the StatusChanged event of GeoCoordinateWatcher, as seen in the following code.

GeoCoordinateWatcher geoCoordinateWatcher;
geoCoordinateWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
geoCoordinateWatcher.MovementThreshold = 100; // in Meters
geoCoordinateWatcher.StatusChanged += (s, e) =>
{
if (e.Status == GeoPositionStatus.Disabled)
{
MessageBox.Show("Please enable your location service by going to Settings ->
Location -> Turn on Location Services option.");
}
};


Another way to check if the location service is enabled is to use TryStart to see if the GeoCoordinateWatcher can be started.

if (!_geoCoordinateWatcher.TryStart(true, TimeSpan.FromSeconds(5)))
{
MessageBox.Show("Please enable Location Service on the Phone.",
"Warning", MessageBoxButton.OK);
}

Next you have to set DesiredAccuracy and provide MovementThreshold in GeoCoordinateWatcher as seen in the foregoing code.

GeoPositionAccuracy.Default will use Wi-Fi or the cell phone towers and depends on the availability of the sources. Windows Phone will automatically choose one to use, and GeoPositionAccuracy.High will use the GPS receiver built into the phone device. MovementThreshold is a very important property to set because MovementThreshold specifies the change in distance in meters before the PositionChanged event notifies the application that new coordinates are available; the lower the value of MovementThreshold, the more accurately the position will be tracked, but you will pay a price in higher power consumption. Microsoft recommends that you set MovementThreshold to at least 20 meters to filter out this noise.

In the following sections, you will learn how to use the Windows Phone Location Service by simulating the behavior of the GPS receiver.

Other  
  •  iPhone Application Development : Implementing a Custom Picker View (part 4) - Tweaking the Picker UI
  •  iPhone Application Development : Implementing a Custom Picker View (part 3) - Reacting to a Picker View Choice
  •  iPhone Application Development : Implementing a Custom Picker View (part 2)
  •  iPhone Application Development : Implementing a Custom Picker View (part 1)
  •  Windows Phone 7 Development : Isolated Storage - Working with Isolated Storage Settings
  •  Mobile Application Security : WebOS Security - Permissions and User Controls
  •  Mobile Application Security : WebOS Security - Code Security
  •  Windows Phone 7 Development : Working with Isolated Directory Storage (part 2)
  •  Windows Phone 7 Development : Working with Isolated Directory Storage (part 1)
  •  iPhone Application Development : Making Multivalue Choices with Pickers - Using Date Pickers (part 3)
  •  iPhone Application Development : Making Multivalue Choices with Pickers - Using Date Pickers (part 2) - Adding a Date Picker
  •  iPhone Application Development : Making Multivalue Choices with Pickers - Using Date Pickers (part 1)
  •  iPhone Application Development : Making Multivalue Choices with Pickers - Understanding Pickers
  •  Sync Your iPad with iTunes : Troubleshooting iTunes and the Sync
  •  Sync Your iPad with iTunes : Manually Transferring Music, Movies, Podcasts, and More on Your iPad (Drag-and-Drop Method)
  •  Windows Phone 7 Development : Internationalization - Using Resource Files to Localize Content
  •  Windows Phone 7 Development : Internationalization - Storing and Retrieving Current Culture Settings
  •  Mobile Application Security : WebOS Security - Development and Security Testing
  •  Mobile Application Security : WebOS Security - Introduction to the Platform
  •  iPhone Application Development : Getting the User’s Attention - Using Alert Sounds and Vibrations
  •  
    Top 10
    Ready Clip - Take Advantage Of These Pen-Sized Bags
    Norton Antivirus 2013 - The Powerful Feature-Rich Antivirus Protection
    Samsung Galaxy Camera - Click And Share Instantly
    Top 10 Camcorders - Jan 2013
    Top 10 Cameras - Jan 2013
    Top 10 DSLRs - Jan 2013
    Accelerate Your PC
    Finding Software Bargains
    Get Free Remote Technical Support
    Club 3D Radeon HD 7990 6GB - Dual GPU Monster
    Most View
    Group Test: Which Are The Best Cases On The Market? (Part 1) - Corsair Graphite 600T Steel Silver Case, Xigmatek Elysium Windowed Case
    Buying Guide: External hard drive - Buffalo DriveStation Velocity 2TB, Freecom Mobile Drive Sq 500GB & Iomega Mac Companion Hard Drive 2TB
    The Cat You Have To Have (Part 2)
    Microsoft ASP.NET 4 : File System Information (part 1) - The Path Class, The Directory and File Classes
    Windows Phone 7 Development : Debugging Application Exceptions (part 2) - Debugging a Web Service Exception
    BizTalk 2006 : Dealing with Extremely Large Messages (part 1) - Large Message Decoding Component
    Inkjet All In One Shootout - Going With Ink (Part 1) - Design & Handling - Brother MFC – J825DW, Canon Pixma MX897, Epson workforce pro WP – 4521, HP Officejet 6700 premium
    Thermaltake Water2.0 Pro - Cool, But Loud
    Motu Machfive 3.0.2 : Stonking samples
    System Center Configuration Manager 2007 : Planning for Internet-Based Clients
    Arduino Lenoardo - A Bargain Microcontroller
    Programming Excel with VBA and .NET : Variables (part 1) - Names & Declarations
    Choosing a... Monitor
    Introducing HTML5 - Choosing a Browser to Interpret HTML5
    Windows 7 : General Maintenance Tools (part 3) - Checking Your Disks for Errors & Optimizing Disk Performance
    Cruiser Air Black – The 1,700 Dollar Basic Phone
    Tiny Motherboard ODroid-X Integrated With Quad-Core Exynos Processor And 1GB RAM
    iphone Programming : Integrating Your Application - Custom URL Schemes
    Installing and Using Windows 7
    Rig Builder – May 2012 (Part 1)