Click here to Skip to main content
13,451,929 members (48,385 online)
Click here to Skip to main content
Add your own
alternative version


5 bookmarked
Posted 6 Apr 2010

Using the GPS, Accelerometer & Vibration Controller

, 6 Apr 2010
Rate this:
Please Sign up or sign in to vote.
How to use the GPS, Accelerometer & Vibration Controller

Want to write an application for Windows Phone 7 Series devices? Need to know where you are? Are you moving? etc…

Well, I do!

Location, Location, Location

“The GeoCoordinateWatcher class supplies coordinate-based location data from the current location provider, which is the location provider that is currently prioritized the highest on the computer, based on a number of factors such as the age and accuracy of the data from all providers, the accuracy requested by location applications, and the power consumption and performance impact associated with the location provider. The current location provider may change over time, for instance, when a GPS device loses its fix indoors and a Wi-Fi triangulation provider becomes the most accurate provider on the computer.”

Here is a very simple example:

GeoCoordinateWatcher watcher = new GeoCoordinateWatcher();
watcher.MovementThreshold = 20;

watcher.StatusChanged += 
	new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.PositionChanged += 
  new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);


Finding the current location on a Windows Phone 7 Series device is very similar to how you would find it using the Windows 7 Sensor & Location Platform! The GeoCoordinateWatcher gives us an event based model to find the current most accurate location!

MovementThreshold specifies the distance that must be moved, in meters relative to the coordinate from the last PositionChanged event, before the location provider will raise another PositionChanged event.

PositionChanged event gets fired every time the current position changes.

Finally to start the watcher, just call Start().

If the position now changes, our watcher_PositionChanged will get fired with the new location.

[TIP] Remember to invoke back to the UI thread if you want to change something in the UI based on the position change!

Read more here (sample).

Am I Moving?

All Windows Phone 7 Series devices will have at least one accelerometer available.

What’s an Accelerometer?

An accelerometer is a device that measures proper acceleration, the acceleration experienced relative to freefall.

Single- and multi-axis models are available to detect magnitude and direction of the acceleration as a vector quantity, and can be used to sense position, vibration and shock. Micromachined accelerometers are increasingly present in portable electronic devices and video game controllers, to detect the position of the device or provide for game input.

Here is a simple example:

AccelerometerSensor accelerometer = AccelerometerSensor.Default;

accelerometer.ReadingChanged += 
  new EventHandler<AccelerometerReadingAsyncEventArgs>(accelerometer_ReadingChanged);


The accelerometer is also event based (like the GeoCoordinateWatcher). Obtain a new instance of the AcelerometerSensor by using the Default property. Now just attach an event handler to the ReadingChanged and call Start().

Once a new reading is available, the accelerometer_ReadingChanged will be called.

Read more here (sample).

Good Vibrations…

All modern phones can vibrate… If you get a new message, on a phone call, etc…

Here is a simple example:

VibrateController vibrate = VibrateController.Default;


Read more here.

With the tighter control over the exact hardware requirements to run the OS, we are finally GUARANTEED that each phone will have a GPS, Accelerometer, 5MP+ Camera, etc.

I know these were very simple examples but just imagine the possibilities! Unfortunately, it’s still a catch-22! These are all real hardware sensors! Difficult to simulate… But if you do use them, they can make your phone applications better!!!


Also read engadget - Windows Phone 7 Series: the complete guide.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

South Africa South Africa
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03-2016 | 2.8.180318.3 | Last Updated 6 Apr 2010
Article Copyright 2010 by rudigrobler
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid