Because OpenLayers is so flexible, it's easy to make third-party software and data work with our maps. Sharing geospatial data is becoming more popular, with services such as Flickr and Twitter freely offering geospatially embedded data. Being able to visualize data often helps us to understand it. Using OpenLayers, we can place geospatial data (say, Twitter posts or Flickr images) on a map and get a clearer picture about the data.
Many popular sites provide an API (Application Programmer Interface) that allows programmers to interact with their data. For instance, both Flickr and Twitter provide APIs that enable developers to view recent updates (photo uploads and tweets). These APIs (but not all APIs) let us get geospatial data that we can use with OpenLayers. Flickr provides some very easy-to-use methods to retrieve data with associated geographic information; so, we'll focus this chapter on building a web-mapping application around Flickr.
You can find out more about APIs and what they support at various websites, a good one is http://www.programmableweb.com.
While Flickr provides a very robust developer API, we'll only interface with Flickr via URL calls that provide access to feeds. Feeds provide information about data, and we can get different kinds of feeds (for example, a specific user's feed or the feed for all users combined). It's really quite easy to do; we just make a call to a URL and specify certain parameters. The base URL we'll call is http://api.flickr.com/services/feeds/geo/?format=kml. The format parameter can be a number of values—KML, JSON, RSS, SQL, and so on. We'll be using KML and JSON in this chapter. When calling this URL, a file in the format you ask for will be returned that contains information about the latest photos uploaded that have geographic information associated with them (that's what geo in the URL is for).
Flickr's API documentation can be found at http://www.flickr.com/services/api/. More information about the Flickr feeds can be found at http://www.flickr.com/services/feeds/.
We can refine the data that is returned by adding additional parameters to the URL. You can specify a user's ID via the ID key, a group via the g key, and tags via the tags key. You can also specify other things, such as a certain coordinate and radius—for now, we'll just be focusing on the tags key.
Let's create a web map application that will pull in data from Flickr and display it on a map. This will allow us to see, geographically, from where photos were submitted. We can, for example, search for bird photos and get an idea where some particular bird species might be common (or at least, commonly photographed and uploaded to Flickr).
The application will provide a search box to enter tags and refresh the map based on them, and allow you to click on points on the map to view the photo and details about it.
We'll break down the development of this application into small steps:
Okay, we've got a goal in mind and broken it down into some manageable steps—we'll start simple and improve in increments until we reach our goal. Let's get started.