Windows Phone SDK Essential Training
Illustration by Don Barnett

Windows Phone SDK Essential Training

with Michael Lehman

Video: Exploring GPS

Now let's take a look at the code behind the GPS portion of this app. We have five controls on the screen here. The first is a button named, start tracking location, and we have three text blocks here for the longitude, latitude and accuracy. Because when you ask for location, you say how much accuracy you want. Like I want my location to be within say five meters. Because location services can end up returning you numbers based on GPS radio or WiFi or some combination of both.
Expand all | Collapse all
  1. 2m 35s
    1. Welcome
      55s
    2. What you need to know to take this course
      51s
    3. Using the exercise files
      49s
  2. 15m 45s
    1. Downloading and installing the Windows Phone tools
      2m 44s
    2. Creating a Hello World application
      9m 32s
    3. Debugging on a Windows Phone device
      3m 29s
  3. 6m 29s
    1. Exploring device capabilities
      2m 58s
    2. Understanding the Emulator
      3m 31s
  4. 8m 51s
    1. Understanding the SDK
      8m 51s
  5. 41m 32s
    1. Introducing the converter
      3m 36s
    2. Creating the user experience (UX)
      13m 35s
    3. Responding to the Application Bar
      2m 40s
    4. Implementing click handlers
      3m 52s
    5. Saving and loading settings
      8m 18s
    6. Preparing your app for shipment
      9m 31s
  6. 20m 49s
    1. Introducing sonnets
      1m 38s
    2. Data binding with Silverlight
      4m 4s
    3. Exploring the Model-View-ViewModel pattern (MVVM)
      4m 3s
    4. Implementing the Master-Detail pattern using pages
      3m 53s
    5. Loading external data
      7m 11s
  7. 50m 27s
    1. Choosing a multipage controller
      3m 13s
    2. Preparing for persistence
      7m 30s
    3. Updating the data model
      7m 2s
    4. Creating the details page
      4m 30s
    5. Bringing it all together
      3m 58s
    6. Cloning a Windows Phone app
      6m 49s
    7. Using SQL CE
      8m 49s
    8. Updating the data model
      2m 24s
    9. Querying and updating the database
      6m 12s
  8. 14m 19s
    1. Working with the camera
      6m 11s
    2. Exploring GPS
      5m 21s
    3. Exploring the accelerometer
      2m 47s
  9. 29m 35s
    1. Introducing recording and playback with XNA
      45s
    2. Capturing sound
      5m 12s
    3. Providing feedback while recording
      5m 50s
    4. Playing a recording
      4m 34s
    5. Persisting a recording
      2m 58s
    6. Listing recordings
      5m 15s
    7. Managing the recording list
      3m 26s
    8. Recording under the lock screen
      1m 35s
  10. 28m 32s
    1. Building the UX
      3m 54s
    2. Using WebClient
      4m 1s
    3. Determining network connectivity
      2m 9s
    4. Leveraging Internet Explorer
      7m 56s
    5. Adding a live tile
      2m 42s
    6. Building a background agent
      7m 50s
  11. 14m 46s
    1. Hello World in C++
      4m 35s
    2. Libraries
      4m 17s
    3. Managed plus managed
      5m 54s
  12. 26m 36s
    1. Exploring built-in controls
      4m 28s
    2. Windows Phone Toolkit
      2m 42s
    3. Introducing Coding4Fun
      3m 14s
    4. Reminders and notifications
      6m 10s
    5. Wallet and In-App Purchase
      1m 34s
    6. File and protocol associations
      1m 59s
    7. Bluetooth
      44s
    8. Integrating speech
      1m 28s
    9. Near field communication (NFC)
      1m 23s
    10. WinRT and legacy Windows Phone APIs
      2m 54s
  13. 12m 15s
    1. Publishing your apps
      2m 49s
    2. Learning from apps in the Windows Phone Marketplace
      1m 23s
    3. Staying in touch with updates and new information from Microsoft
      2m 34s
    4. Looking at Windows Phone 7 app reviews
      44s
    5. Exploring web sites books and other useful links
      4m 45s
  14. 1m 34s
    1. Farewell
      1m 34s

Start your free trial now, and begin learning software, business and creative skills—anytime, anywhere—with video instruction from recognized industry experts.

Start Your Free Trial Now
please wait ...
Watch the Online Video Course Windows Phone SDK Essential Training
4h 33m Beginner Jun 11, 2013

Viewers: in countries Watching now:

Discover how to build professional apps that encompass the 17 major feature areas of Windows Phone, from XAML to multimedia to network access. In this course, author Michael Lehman details the standard hardware device configuration, teaches how to navigate the development environment, and explores the Windows Phone APIs. The course shows how to build sample applications while learning Windows Phone concepts and frameworks, including the Metro design language.

Topics include:
  • Downloading and installing the tools
  • Understanding the SDK
  • Designing the user experience (UX)
  • Implementing commands
  • Data binding with Silverlight
  • Exploring the Model-View-ViewModel (MVVM) pattern
  • Loading external data
  • Capturing data from the camera, GPS, compass, and accelerometer
  • Recording and playing sound
  • Implementing persistence with isolated storage
  • Leveraging built-in tasks, choosers, and launchers
  • Expanding the available controls using the Silverlight and Coding4Fun toolkits
  • Cloning a Windows Phone app
  • Learning how to publish your app
Subject:
Developer
Software:
Windows Phone
Author:
Michael Lehman

Exploring GPS

Now let's take a look at the code behind the GPS portion of this app. We have five controls on the screen here. The first is a button named, start tracking location, and we have three text blocks here for the longitude, latitude and accuracy. Because when you ask for location, you say how much accuracy you want. Like I want my location to be within say five meters. Because location services can end up returning you numbers based on GPS radio or WiFi or some combination of both.

It may actually give you back an accuracy that is either more accurate or less accurate than you actually requested. And then we finally have a map it button, which allows us to invoke the map test. Based on the data that we got from the longitude and latitude requests from the GPS. So let's go look at the code. In order to access location services we need System.Device.Location and Windows.Devices.Geolocation. In order to access the map we need to use Microsoft.Phone.Task.

The thing which gets us the location is something called a Geolocator. So, here is the declaration of our Geolocator object and the location longitude, latitude and accuracy come back in something called a Geoposition. So, here we allocate our Geoposition object. We come into the page, we allocate a new Geolocator and set our desired accuracy to ten meters. We look at the start tracking location method here in button1_Click. What we do is disable our existing buttons, so the user can't tap them multiple times.

We set the longitude and latitude text blocks to the word locating with an ellipsis at the end, and then we attempt to go get the current location. In order to do that we set up two timespans. There's an API called GetGeopositionAsync, that takes two timespan objects. The first one max age is how old of a GPS location are we willing to accept. In a real world situation, you're going to want to typically set this to maybe one minute or five minutes. Because you don't necessarily have to have the absolutely precise up-to-date geolocation.

If you do that, it can be heavy on battery usage. We've set it for the demo here to five seconds so that, as we click on the map, we can get immediate feedback. In real life, you probably want to set this to a timespan from minutes of one, two, three, four, five. Timeout has to do with how long between the time that you ask the GPS radio for a synch and when it's going to time out and say, hey I can't find the satellite. Thirty seconds is a real world reasonable number. GetGeopositionASync is a new Windows 8 style WinRT asynchronistic API.

We're going to take one step backwards here and look at the fact that we declared this method private async void. The reason we did that is so that we could come down here and say currentLoc equals await gl.GetGeopositionAsync. This is a much simpler solution than the one you had to use for Windows Phone 7, in which you had to set up your own custom event handlers. And deal with the callbacks. Once we get back to our location, we take our currentLoc which is a geoposition and we ask for a Coordinate, Latitude and then we turn it into a string. Similarly we do the same things for Longitude and Accuracy. And now that we have a geoposition we enable our map it button. Now you noticed we didn't check to see whether or not the location was valid. That's because the way GetGeopositionAsync works is that it will throw an exception if it can't get a location for you. So we have two separate exception handlers here. We have a catch for Unauthorized Exception, which is what happens when the user has disabled Access to location services.

And we have a regular kind of exception which is what happens when you can't get a GPS fix. And finally, in our try catch finally, we reset our go button to true so you can request a location over and over again. So that's how it happens that we update the text blocks on the screen with the longitude, latitude, and accuracy. Finally, let's take a look at how we map things. Down here in our button2_Click handler, we have something simply that says, do we have a geoposition object in currentLoc? If we have one, creating a map is as simple as instantiating a map task. Setting the center point into the map equal to a geocoordinate and passing in the latitude and the longitude, like this.

The zoom Level is anywhere from 1 to 20. 1 represents vision of the entire world and 20 represents the highest accuracy you can get, like 5 feet in front of a building. Somewhere between 10 and 12 is a reasonable size for navigating around the city in terms of something similar to a map you would have on paper. And once you set that up, the last thing you have to do is simply say map test dot show and the operating system handles everything else for you. Once again, this is way simpler than the way it was in Windows Phone 7 where you had to use big maps and set up things. And either host a web browser or use a seperate browser app. This is something the system handles for you automatically. Next up, let's take a look at how the accelerometer code works.

Find answers to the most frequently asked questions about Windows Phone SDK Essential Training .


Expand all | Collapse all
please wait ...
Q: This course was updated on June 10, 2013. What changed
A: This course was updated on June 10, 2013. Revisions include:
  • Over two dozen movies revised to reflect changes to Windows Phone 8 (released October 2012)
  • New instructions for downloading and installing to Windows Phone toolset
  • New instructions for working with Windows Phone 8 device data
  • New chapter on native development with C++
  • New chapter on advanced Windows Phone features including in-app purchasing with Wallet, reminders and notifications, Near Field Communication (NFC), and more.
 
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

Please wait... please wait ...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ .

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

* Estimated file size

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed Windows Phone SDK Essential Training.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member ?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferences from the dropdown menu.

Continue to classic layout Stay on new layout
Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Learn more, save more. Upgrade today!

Get our Annual Premium Membership at our best savings yet.

Upgrade to our Annual Premium Membership today and get even more value from your lynda.com subscription:

“In a way, I feel like you are rooting for me. Like you are really invested in my experience, and want me to get as much out of these courses as possible this is the best place to start on your journey to learning new material.”— Nadine H.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked
Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.