Return to Video

Writing the Button Code - Pro Tips

  • 0:01 - 0:02
    So now I can run my app but
  • 0:02 - 0:06
    it's probably not going to work
    because I haven't set up the API key.
  • 0:06 - 0:09
    The next thing that you should do
    is to go to the Google console and
  • 0:09 - 0:14
    then based on the name of the app,
    like in this case you can see
  • 0:14 - 0:19
    my app is at
    com.google.devplat.lmoroney.maps3_2.
  • 0:19 - 0:22
    I need to set that up
    within the API console.
  • 0:22 - 0:24
    So if you remember in
    the earlier lesson,
  • 0:24 - 0:28
    when we created public API access,
    we had an API key and
  • 0:28 - 0:32
    we had Android applications that
    were allowed to use that API key and
  • 0:32 - 0:36
    these were defined by the SHA 1,
    in this case the debug one.
  • 0:36 - 0:39
    Followed by a semi-colon,
    followed by the name of the application.
  • 0:39 - 0:42
    Now you can see here I've done
    the same thing, the same SHA 1.
  • 0:42 - 0:47
    And now this application,
    com.google.devplat.lmoroney.maps3_2.
  • 0:47 - 0:51
    This is the most common place you go
    wrong in writing applications and
  • 0:51 - 0:52
    creating them.
  • 0:52 - 0:55
    Is that either you've named this
    incorrectly, you've made a mistake
  • 0:55 - 1:00
    with the SHA 1 key, your API key is
    wrong or something along those lines.
  • 1:00 - 1:05
    So if you this API key beginning
    with Alza and ending with d or
  • 1:05 - 1:09
    z8, if I go back to Android Studio and
  • 1:09 - 1:13
    go to my Android manifest,
    you can see I have, it was Aiza.
  • 1:13 - 1:15
    Sorry, not Alza.
  • 1:15 - 1:20
    You can see I have the API key set up
    here correctly and it's definitely
  • 1:20 - 1:24
    the same name application
    com.google.devplat.lmaroney.maps3_2.
  • 1:24 - 1:29
    A little pro tip is if you ever
    refactor it, and you'll think you've
  • 1:29 - 1:32
    refactored and you've gotten everything
    changed if you refactor the name of your
  • 1:32 - 1:36
    package and you'll find that
    maps don't actually work.
  • 1:36 - 1:38
    What can happen is that
    while your refactor it and
  • 1:38 - 1:43
    while you've changed it on the console
    in refactoring in buildup Gradle
  • 1:43 - 1:46
    the application id string
    here may not change.
  • 1:46 - 1:49
    So if you ever refactor your app and
    find trouble, just make sure to
  • 1:49 - 1:54
    come back into your buildup Gradle and
    make sure that the string here with
  • 1:54 - 1:57
    an application ID matches
    the refactoring that you've done.
  • 1:58 - 2:00
    So let's now run the application and
    take a look.
  • 2:01 - 2:02
    And here it is again.
  • 2:02 - 2:04
    Here's the application running.
  • 2:04 - 2:05
    You can see I'm centered
    on New York City.
  • 2:05 - 2:08
    I have my three buttons
    laid out across the top.
  • 2:08 - 2:10
    Remember, that was
    the horizontal layout.
  • 2:10 - 2:14
    And then the entire thing is in a
    vertical layout with the button panel on
  • 2:14 - 2:18
    top of the actual map fragment and
    of course I can continue to pan and
  • 2:18 - 2:20
    zoom around the map if I so desire.
  • 2:20 - 2:22
    And when I press the buttons,
    for example the hybrid button,
  • 2:22 - 2:24
    I now get a hybrid map, which you'll
    see more closely if I zoom in, so
  • 2:24 - 2:26
    you can see the street
    names were highlighted and
  • 2:26 - 2:27
    the streets themselves were highlighted.
  • 2:27 - 2:29
    And when I press the buttons for
    example, the hybrid button,
  • 2:29 - 2:31
    I now get a hybrid map, which you'll
    see more closely if I zoom in.
  • 2:31 - 2:33
    So I have the satellite
    photographic map,
  • 2:33 - 2:37
    but with the lines of roads and things
    laid out on top of it, which is really,
  • 2:37 - 2:40
    really useful when you're
    navigating around places.
  • 2:40 - 2:44
    Or if I just want the pure
    satellite picture, here it is.
  • 2:44 - 2:45
    So it was as simple as that.
  • 2:45 - 2:48
    Very little coding and you're beginning
    to see that you can build some pretty
  • 2:48 - 2:49
    powerful functionality.
Tytuł:
Writing the Button Code - Pro Tips
Opis:

more » « less
Video Language:
English
Team:
Udacity
Projekt:
ud876-4 - Google Play Services - Maps
Duration:
02:51

English subtitles

Revisions Compare revisions