Hello.
Welcome to Google Developers Live.
I'm Paul Saxman, a developer advocate on the Google Maps API
team.
In this video, I cover the basics
of adding markers to a map using the Google Maps Android API V2.
Markers are the fundamental way to show position of something
on a map.
Something in this context can be a place, such as a city
venue or landmark, or it could be a transient or moving object
such as a person or vehicle.
Essentially, markers can be used to represent anything
that has a global position in latitude and longitude
coordinates.
Adding a marker to the map is as simple as calling addMarker
on the Google Map object with a marker options
object as a parameter.
An instance of a marker is returned from addMarker
so that you can later update or remove the marker.
You can remove a map marker by calling the remove method
on the marker instance.
When creating a marker, the marker options object
needs to be configured with a position in lat
long coordinates, but it also supports
a number of other optional parameters.
For example, you can create an invisible marker,
which you can later make visible.
Or you can set the transparency for a marker
using the alpha property.
The default marker is a red inverted tear drop,
which should be familiar to most users.
However, you can easily change the color of a marker
or provide your own marker image using the icon
method and a bitmap descriptor factory object.
We'll cover these techniques in a video
on creating custom markers, however,
since there are a number of ways that you
can change a marker's appearance.
After a marker has been created, most
of its properties like its position, visibility, and icon
can be changed by calling corresponding mutator
methods on the marker class.
For example, if you want to toggle
the visibility of a marker, you can
call a setVisible method of a marker instance.
Toggling marker visibility is a great way
to implement place filtering, since making
an initially invisible marker visible
is faster than creating a new marker altogether.
For example, if you want to allow the user to hide or show
hotels with specific price or cost levels,
you'll likely want to use marker visibility instead of creating
new markers altogether to get the best performance.
If you want to show a small amount of information
on the map along with the marker,
you can add a title and snippet to your marker using
the corresponding methods on the marker options class.
The title and snippet are displayed
in an info window, a bubble over the marker when
the user touches the marker.
You can also programmatically show or hide the info window
using the showInfoWindow and hideInfoWindow
methods of a marker instance.
You can fully customize the appearance
of the info window using an info window adapter.
However, since there are a couple ways
that you can customize an info window,
we'll cover these techniques in a separate video as well.
If you want to take some other action when a user touches
a marker besides showing an info window,
you can implement an on-marker click listener
and assign an instance of your listener
to the Google Map class.
When a user touches the marker, the on-marker click method
of your adapter instance is called with a reference
to the marker that was clicked.
It can therefore be useful to maintain a hash map of markers
that you've created in order to look up and display more
information about the place or object associated
with a marker.
For example, if you use markers to represent hotels
and you want to show details about a hotel
in a separate view when a user touches a hotel marker,
you can use a hash map to look up the hotel description using
a clicked marker as the key.
So now you should know how to get started with markers.
If you'd like more information, check out our documentation
and watch a show about custom markers.
In the meantime, have fun making remarkable maps.
Thanks for joining and hope to see you soon.