Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Start Coding the Location App

Get Embed Code
4 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. Okay, great, we now have a UI defined
    and our Android manifest is almost done.
  2. But because we're using Google Services,
    there is one meta tag that we need to
  3. add, and that's just to specify that
    we're using the Play Services Library.
  4. We do that like this.
  5. The metadata tag is used
    within the application tag and
  6. it should be a sibling of the activity,
    not a child.
  7. Within that, your specified Android is, and
  8. the value for this is
  9. Now as you can see here
    it's showing up red.
  10. It's showing up as an error
    you cant resolve symbol,
  11. but we're going to fix that in a moment.
  12. And also once that's been fixed, once
    your application has been configured to
  13. use these services libraries
    whenever you compile,
  14. this will be filled in automatically
    with the correct number.
  15. So let's go ahead and do that.
  16. So in order to do that there's one other
    place that we need to ensure that we're
  17. using the libraries for the services and
    that's in the build.gradle for
  18. the app itself.
  19. So if I go into the build.gradle for
    the app,
  20. down here you can see the dependencies
    at bottom of build.gradle.
  21. We're going to add a new
    dependency in here.
  22. So what we want to add is quite simply,
  23. to compile conduct
  24. Now it's important to note that
    your version here may be different.
  25. It depends on what you're using, and
  26. what version of Play Services
    you've installed.
  27. You can take a look in your system to
    see what versions have been installed
  28. for you.
  29. And I'm just using this plus,
    just to make life a little bit easier.
  30. I believe I have
  31. But of course, by the time your
    watching this Play Services
  32. might be in version 7 or later and as
    you can see here, you should avoid using
  33. plus in version numbers because it
    can lead to unpredictable behavior.
  34. But I'm just going to leave it in for
    the time being, for simplicity.
  35. But do note when you're building your
    applications that you should use
  36. the correct version number here.
  37. So now, once we've done this, we're
    going to go to our main activity, and
  38. we're going to access
    the location provider.
  39. Now, in our main activity, remember that
    it contains just a single text view.
  40. When the user runs the app,
  41. we want it to get the current
    location using location services, and
  42. write the latitude of the current
    location into that text view.
  43. In order to do this, we're going to
    need to write some code in the activity.
  44. This code will create
    the Google API Client, and
  45. set up the required call backs to catch
    responses back from location services.