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

(gtxtreme123) #1

Chapter 34  Maps


Listing 34.8  Saving out query results (LocatrFragment.java)


private class SearchTask extends AsyncTask<Location,Void,Void> {
private Bitmap mBitmap;
private GalleryItem mGalleryItem;
private Location mLocation;


@Override
protected Void doInBackground(Location... params) {
mLocation = params[0];
FlickrFetchr fetchr = new FlickrFetchr();


}


@Override
protected void onPostExecute(Void result) {
mMapImage = mBitmap;
mMapItem = mGalleryItem;
mCurrentLocation = mLocation;
}
}


With that, you have the data you need. Next up: making your map show it.


Working with Your Map


Your SupportMapFragment creates a MapView, which is, in turn, a host for the object that does the real
work: GoogleMap. So your first step is to acquire a reference to this master object. Do this by calling
getMapAsync(OnMapReadyCallback).


Listing 34.9  Getting a GoogleMap (LocatrFragment.java)


public class LocatrFragment extends SupportMapFragment {
...
private static final int REQUEST_LOCATION_PERMISSIONS = 0;


private GoogleApiClient mClient;
private GoogleMap mMap;
private Bitmap mMapImage;
private GalleryItem mMapItem;
private Location mCurrentLocation;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);


mClient = new GoogleApiClient.Builder(getActivity())
...
.build();


getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
});
}

Free download pdf