English titulky

← Show Shapes Code

Získať kód na vloženie
4 Languages

Ukazujem Revíziu 3 vytvorenú 05/25/2016 od Udacity Robot.

  1. So I'm just going to show how I added
    the polyline to the map with all my
  2. different ice rinks.
  3. So to draw the polyline, I set up
    the latitudes and longitudes for
  4. all the different ice rinks, Renton,
    Kirkland, Everett, Lynnwood, etc.
  5. And this time I'm just setting
    them as LatLng objects.
  6. Earlier they were marker options,
    but now they're just latitudes and
  7. longitudes.
  8. I set up my camera position to be
    exactly as I did in the earlier sample.
  9. Now in my onMapReady, I just move
    the camera to my camera position,
  10. which is Seattle.
  11. And then to draw the polyline
    I just call map.Polyline.
  12. It's a new Polyline object,
    geodesic true,
  13. and then I just add all
    of the latitudes and
  14. longitudes that I had created earlier,
    Renton, Kirkland, Everett, Lynnwood.
  15. Notice that I begin at Renton and
    I also add Renton at the end.
  16. And then this just closes the shape.
  17. Because what will happen when you draw a
    polyline is it will draw from Renton to
  18. Kirkland, from Kirkland to Everett,
    from Everett to Lynnwood, etc.
  19. So, if I want to close the shape,
  20. I just want to go back to
    the initial one at the end.
  21. And then I will get all my rinks drawn
    into a polygon like shape by adding
  22. a polyline.
  23. And this is what it will look like.
  24. Here you can see on my tablet I
    have the same map of Seattle, and
  25. I have all the endpoints
    of the different rinks.
  26. My home rink of Renton that I showed
    earlier on is the beginning and
  27. ending point, and then the polylines
    get drawn from Renton to other rinks.
  28. So for example,
    this is the rink in Kingsgate.
  29. You can see,
    Kingsgate highlighted there.
  30. Or I can go all the way
    the rink in Everett, etc.
  31. So, these are the polylines that I've
    drawn from me connecting the rinks.
  32. And because I just joined the last rink
    at ShoWare back to Renton in my code
  33. the shape gets completed.
  34. And as you can see here,
    my second last one was ShoWare.
  35. I then added Renton and
    the shape got completed.
  36. So my polyline actually
    became a polygon.
  37. You can actually also
    do a map.addPolygon and
  38. specify the endpoints and
    it will auto close it for you.