Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 34  Maps


More often, it is easier to provide a list of points that you would like this rectangle to encompass.
LatLngBounds.Builder makes it easy to do this: Simply create a LatLngBounds.Builder and call
.include(LatLng) for each point your LatLngBounds should encompass (represented by LatLng
objects). When you are done, call build(), and you get an appropriately configured LatLngBounds.


With that done, you can update your map in two ways: with moveCamera(CameraUpdate) or
animateCamera(CameraUpdate). Animating is more fun, so naturally that is what you used above.


Next, hook up your updateUI() method in two places: when the map is first received and when your
search is finished.


Listing 34.12  Hooking up updateUI() (LocatrFragment.java)


@Override
public void onCreate(Bundle savedInstanceState) {
...
getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
updateUI();
}
});
}
...
private class SearchTask extends AsyncTask<Location,Void,Void> {
...
@Override
protected void onPostExecute(Void result) {
mMapImage = mBitmap;
mMapItem = mGalleryItem;
mCurrentLocation = mLocation;


updateUI();
}
}

Free download pdf