Return to Video

Exploring Camera Code

  • 0:00 - 0:05
    In code, to create a camera position,
    you use a CameraPosition.builder.
  • 0:05 - 0:08
    This builder takes the properties that
    you've just seen, such as the target,
  • 0:08 - 0:10
    which is the latitude and longitude.
  • 0:10 - 0:14
    The zoom that you want, how far you
    want to be zoomed into the map.
  • 0:14 - 0:17
    The baring of the camera,
    the direction that it's pointing in and
  • 0:17 - 0:18
    the tilt of the camera.
  • 0:18 - 0:21
    When you've set all of these
    properties and you build it,
  • 0:21 - 0:25
    you'll then get a camera position and
    I've just called it cp here.
  • 0:25 - 0:29
    Then if you want to instantaneously
    update the map to show the location that
  • 0:29 - 0:34
    the camera is pointing at with these
    values, you call map.movecamera and
  • 0:34 - 0:38
    you pass it, a camera update
    factory.newcameraposition
  • 0:38 - 0:41
    with that camera position
    that you've just defined.
  • 0:41 - 0:44
    Like I said, this will instantaneously
    move the map to that location.
  • 0:44 - 0:47
    But you may also want to animate
    the map to that position
  • 0:47 - 0:51
    where you'll see a flyover type effect
    where you'll fly to the new location.
  • 0:51 - 0:54
    And to do this,
    you'll use animateCamera.
  • 0:54 - 0:58
    And animateCamera takes the same
    CameraUpdateFactory.newCameraPosition
  • 0:58 - 1:02
    ith your camera position, but it also
    has a couple of extra parameters.
  • 1:02 - 1:06
    One is the time in milliseconds
    that you wanted to take to fly to
  • 1:06 - 1:07
    the new location.
  • 1:07 - 1:10
    Of course you might want to zip
    over there really quickly or
  • 1:10 - 1:14
    you might want to slow pan up over
    the Earth and down to the new location.
  • 1:14 - 1:16
    You'd specify the time
    in milliseconds here.
  • 1:16 - 1:20
    So if you wanted to take five seconds,
    you'd put 5,000 milliseconds in here.
  • 1:20 - 1:23
    And the callback function gets called
    when the animation is complete.
  • 1:23 - 1:26
    So if you want to execute some
    code once the animation is done,
  • 1:26 - 1:28
    you could put it in
    that callback function.
  • 1:28 - 1:32
    If you don't want to use a callback
    function, you can just put a null here.
  • 1:32 - 1:34
    Let's take a look at
    an animated camera in action.
Title:
Exploring Camera Code
Description:

more » « less
Video Language:
English
Team:
Udacity
Project:
ud876-4 - Google Play Services - Maps
Duration:
01:35

English subtitles

Revisions Compare revisions