Mystery Incorporated


Programming, photography, news, culture, and cartoons

home | rss | atom

Add to Google

Mapping America’s Farmers Markets


June 28th, 2013 [programming]

marketsDo you wish you could discover local farmers markets as you visited new places? Here’s a web app that makes it easy: the Market Mapper application. It uses data from the U.S. Department of Agriculture of all farmers markets in the U.S.A.

The program uses your current location to display the closest farmers markets. You can also type a place in the “location” field. As you pan the map, hit “find markets” to look for more locations.

Hovering over a marker will display the name and address of the market. Most markets will also show a list of what they sell, as well as their schedule.

If your market is missing or has outdated information, go to usdadirectoryupdate.com to manage your market’s data.

Developing the Application

I got the idea for the application at a recent DC Web API User Group meetup, where a speaker from the U.S. Department of Agriculture discussed their new farmers markets API. You can access the data on their own site at farmersmarkets.usda.gov.

Their API offers two calls. The APIs are accessed via a simple URL which can be accessed in JavaScript, and they respond with JSON. The first function takes either a zip code or a pair of coordinates and returns a list of nearby markets. The format is

search.ams.usda.gov/farmersmarkets/v1/data.svc/zipSearch?zip=ZIP

or

search.ams.usda.gov/farmersmarkets/v1/data.svc/locSearch?lat=LATITUDE&lng=LONGITUDE

It seems to always return 19 items.

I wish they had a method for finding everything inside a bounding box, like

search.ams.usda.gov/farmersmarkets/v1/data.svc/search?n=NORTH&s=SOUTH&w=WEST&e=EAST

And a way to page through results would be awesome, or at least show more than 19 markets. And there are no ways to further filter the results. It would be nice to query for markets that are open at a given date and time.

The response includes only the name of each market and the ID number. In order to place them on a map you need to make an additional call for every single market, using the ID code. The USDA could make this much more efficient by including the coordinates in the response of the main list.

Getting full details uses the following API call:

search.ams.usda.gov/farmersmarkets/v1/data.svc/mktDetail?id=ID

It returns only four bits of information: the address, a link to map on Google, a description of the products offered, and the schedule. I wish the results were more atomic. In order to get the latitude and longitude, I have to parse the google link. And it’s hard to do calculations on the schedule when it’s just a big string of text. We could provide a lot more functionality if the API offered more control.

But this is a good start for a government agency. I’m guessing this is the definitive list of farmers markets in the country. Try out the Market Mapper and see what you can discover.

One Response to “Mapping America’s Farmers Markets”

Site by M.V. Jantzen
mvs202 "at" gmail.com
twitter.com/mvs202