Log.v(“ThreeTips”, ”#2”)
1 — Zoom to all markers on Android Map
Lets say you have hundreds of locations and you want to add them as marker. It is pretty simple actually. You can easly add a marker to map like
But what if you want to zoom all markers after adding all markers? Don’t worry, maps api has that option too. You can easily create LatLongBounds and pass that bounds to CameraUpdateFactory class. Second parameter of newLatLngBounds(bounds, 0) is an integer. You can specify padding, in order to inset the bounding box from the map view’s edges.
2 — Custom InfoWindow in Google Maps
You can inflate a custom view layout to info window. Here is simple implementation about it.
getInfoWindow callback returns view for info window view. I omit that for this implementation. I only inflate view for content.
Normally we pass data to adapters. But here there is an exceptional situation. We don’t have position. We only have selected Marker object. And you can not set data to marker. That is why we should use hashmap for that. We need to hold HashMap<Marker, Object> global variable.
I expect this should work without error. I run it and yes I was right. I didn’t get any error. But picasso didn’t load url into image. After some research, I understand why picasso didn’t load url. Because when getInfoContents is called, InfoView only shows it snapshot. Yes, It is just an layout snapshot. I need to write callback for image loading then update my marker infoview.
Then update my loading image logic.
Then set InfoWindow adapter to map.
3 — Custom Font using Data Binding
Lots of android developers use a library for using custom fonts in their apps. I want to show how databinding makes it easy. It just a one static method and one line of xml code.
BindingAdapter lets you create custom attributes in your xml layouts. For instance, TextViews does not have android:font=”robotoBlack.ttf”. With databinding we can create an attribute like that.
That’s all. Don’t forget to add fonts under “src/main/assets/fonts/” folder.
Happy Coding.