Introduction to Maps API on Android Wear (100 Days of Google Dev)

Introduction to Maps API on Android Wear (100 Days of Google Dev)


HOI LAM: Android
Wear is great for quick, glanceable
information that lets you stay in the present
whilst being connected, so naturally one of
the most requested functions is to display
locations on the map. I’m Hoi Lam, and with the latest
Google Play services update, Google Maps API has
arrived on Android Wear. This means best in class
mapping functionality is only a few lines of code away. In this Tech Byte, I’ll run
you through some common use cases for the Maps
API on Android Wear, giving you a head start
on how to implement them. Before we begin, some good news. The Google Maps
API on Android Wear is based on the same APIs on
Android phones and tablets. As a result, if you have used
the Google Maps API on Android before, you’ll
feel right at home. One of the most common use cases
is simply displaying a map. Your app might need to show
a marker to denote a landmark or display a running route. In this case, you can use to
Map Fragment, or Map View, and apply for a
Google Maps API key, adding markers and polylines
when they’re needed. All of this functionality
is available to you using the same Maps
API you’re already familiar with on Android,
with just one caveat though. Android Wear
reserves the gesture of swiping from left
to right for dismissing the current application. If you do not need
your map to pan around, this will continue to work. However, if you need your
map to move around and pan, we need to override this
particular dismiss gesture to reduce confusion and actually
let our user exit our apps. To do this, you need to
implement the Dismiss Overly View, this red
circle with a cross, and attach it to the
long click event. The view will handle
the dismiss action. Another common use case is to
select a location on the map so that your friend, or your
taxi, can meet you there. To implement this,
you can place a marker in the middle of the screen
and let your user pan around the map. This indicates the selected
location within a map fragment element. Then use the Google Map
onCameraChange listener to detect if the user has
panned around the map. You can access the
new location through the
cameraPosition.target.latitude and longitude. You can then send this
information to the recipient, be it a friend or a taxi driver. For more technical information
about how to implement the use case we described
in this Tech Byte, please head over to
our Maps API blog post. In addition, more in-depth
reference information is available on the
Google Developer portal via this second link. I’m Hoi Lam. Android Wear is
designed for a user to stay connected
whilst on the move. With the Google Maps
API on Android Wear, developers have a powerful
tool backed by Google Maps. So let’s keep our users
moving in the real world.

Leave a Reply

Your email address will not be published. Required fields are marked *