CHRISTOPHER BROADFOOT: Hello.
Welcome to this week's Google Maps Developer Shortcuts.
I'm coming to you from the Sydney studio, where we have
new couches and I have a little more facial hair after
Google I/O. Speaking of I/O, if you haven't already watched
my talk, I strongly suggest you do.
It's called When Android Meets Maps, and it gives you a run
down of the Google Maps Android API and some of the
cool things you can do with it.
So speaking of cool things, I talked a little bit about this
utility library at I/O, and today, I've extended it a
little bit more.
So it's called the android-maps-utils library.
It has a poly util, a spherical util, and as of
today, a Bubble Icon Factory.
So let's talk about poly util just very quickly.
At the moment, it has one function.
It's decode.
It will take an encoded poly line or
polygon, which is a string.
You might get this from the Google Directions API, and it
will give you back a list of latitude and longitude points.
Spherical util is great if you need to do things like compute
distances between points, areas, headings between two
points, or simply interpolate.
Perhaps you want to animate a marker
between Sydney and France.
You can cycle through that third value to get a nice
smooth line between Sydney and France.
There's many more functions.
These are just a small sampling.
So let's talk about Bubble Icon Factory.
Essentially, it just lets you generate
marker images like this.
These sort of look like info windows, but each marker is
always showing.
So this is great for showing small snippets of information
such as house prices, as you can see here.
It's really simple.
You just create a new Bubble Icon Factory, and
you call Make Icon.
And you pass out a string, and that string will be shown
within that marker icon.
You get back a Bitmap, which you can pass through to the
Bitmap descriptor factory.
And you just add that to your marker
through the icon option.
Of course, you can use setIcon to change that marker later.
So you can change the color it it.
Here you can see that we've got white
markers and green markers.
So you can just call Set Style on the factory and just say
that you want a green style.
You can change these styles at any time, so you can, for
example, set a whole bunch of styles on the factory or maybe
create separate factories for two
different types of markers.
It's really up to you.
So the other neat thing about this is that
you can rotate markers.
Here you can see that we've got markers that
are pointing downwards.
So this is great for a small snippet of information once
again, like house prices, where you don't really want to
interfere with the map too much.
So we've gone a little bit crazy with colors here.
You might want to stick to one or two different colors.
But the library ships with a lot of different styles that
might suit your application.
It's just the orange, red, purple, blue and green.
So as I said, you can set the rotation of the marker.
You can rotate the marker itself or just the
content within it.
So with these markers where the text is just pointing
down, we just set the content rotation to 90 degrees.
Now, you could have markers that are sticking outwards
like a little tag as well.
That's all quite possible.
You can also change the content view completely.
For instance, if you'd like to display an image within that
little bubble, you can do that too.
You just call Set Content View.
Perhaps you want to pass an image view down to that.
And instead of calling Make Icon with a string, you just
call Make Icon, and you get back that Bitmap.
So a little tip--
these can be run off the main thread, off the UI thread, so
you could go and generate all of these in parallel or in the
background, perhaps in an async task.
And once it's generated back on the UI thread, go on, put
that marker onto the map.
So go and check it out.
It's on github.com/googlemaps.
It's distributed as an Android library project, much like
Action Bar Sherlock or something like that.
You're probably familiar with it.
Actually, in fact, you're already familiar with it if
you're using the Maps API, because the Google Play
services client is distributed as a library project.
So just go ahead and drop that into your project, and you can
start using this poly util, spherical util, and the Bubble
Icon Factory.
Well, I hope that helps, and I'll see you around next time.
Thank you.