Getting More Location Data
And then pull that data out of your Flickr JSON response.
Listing 34.6 Pulling data from Flickr JSON response (FlickrFetchr.java)
private void parseItems(List
throws IOException, JSONException {
JSONObject photosJsonObject = jsonBody.getJSONObject("photos");
JSONArray photoJsonArray = photosJsonObject.getJSONArray("photo");
for (int i = 0; i < photoJsonArray.length(); i++) {
JSONObject photoJsonObject = photoJsonArray.getJSONObject(i);
GalleryItem item = new GalleryItem();
item.setId(photoJsonObject.getString("id"));
item.setCaption(photoJsonObject.getString("title"));
if (!photoJsonObject.has("url_s")) {
continue;
}
item.setUrl(photoJsonObject.getString("url_s"));
item.setOwner(photoJsonObject.getString("owner"));
item.setLat(photoJsonObject.getDouble("latitude"));
item.setLon(photoJsonObject.getDouble("longitude"));
items.add(item);
}
}
Now that you are getting your location data, add some fields to your main fragment to store the current
state of your search. Add one field to stash the Bitmap you will display, one for the GalleryItem it is
associated with, and one for your current Location.
Listing 34.7 Adding map data (LocatrFragment.java)
public class LocatrFragment extends SupportMapFragment {
...
private static final int REQUEST_LOCATION_PERMISSIONS = 0;
private Bitmap mMapImage;
private GalleryItem mMapItem;
private Location mCurrentLocation;
...
Next, save those bits of information out from within SearchTask.