Flickr Geosearch

The next step is to add the ability to search for geographic locations on Flickr. To do this, you perform a regular search, but you also provide a latitude and longitude.

In Android, the location APIs pass around these location fixes in Location objects. So write a new buildUrl(…) override that takes in a Location object and builds an appropriate search query.

Listing 33.12  New buildUrl(Location) (FlickrFetchr.java)

private String buildUrl(String method, String query) {
    ...
}

private String buildUrl(Location location) {
    return ENDPOINT.buildUpon()
            .appendQueryParameter("method", SEARCH_METHOD)
            .appendQueryParameter("lat", "" + location.getLatitude())
            .appendQueryParameter("lon", "" + location.getLongitude())
            .build().toString();
}

And now write a matching searchPhotos(Location) method.

Listing 33.13  New searchPhotos(Location) (FlickrFetchr.java)

public List<GalleryItem> searchPhotos(String query) {
    ...
}

public List<GalleryItem> searchPhotos(Location location) {
    String url = buildUrl(location);
    return downloadGalleryItems(url);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.108.168