Reputation: 5576
I am working in python on a website that lets users search for used textbooks. When a user performs a search and selects a result to view, the site displays some details about the book (title, picture, price comparison across different websites, etc.), as well as, ideally, a map showing where the different sellers are located in the United States.
What I am looking for is a nice way to plot points on a U.S. map by zipcode, since the search results I get from book sellers' APIs all provide that information. One idea is maybe to use pymaps (insufficiently documented, but a nice example here: http://www.lonelycode.com/2008/12/04/google-maps-and-django/) to do it. From my understanding, I would need to start by converting the initial latitude, longitude, and zoom parameters (following the example somewhat) into a good full-USA base scene. Then, perhaps, I could find a way/module to convert zip codes to latitude/longitude coordinates and make the maps as desired. Is this a feasible approach, or is going to have more complicated details than I can forsee? Is there something out there that is even easier (provided it requires ONLY Python and no Javascript, etc.)
Upvotes: 3
Views: 8700
Reputation: 608
Try pyzipcode! Use this code as reference for your problem!
>>> from pyzipcode import ZipCodeDatabase
>>> zcdb = ZipCodeDatabase()
>>> zipcode = zcdb[54115]
>>> zipcode.zip
u'54115'
>>> zipcode.city
u'De Pere'
>>> zipcode.state
u'WI'
>>> zipcode.longitude
-88.078959999999995
>>> zipcode.latitude
44.42042
>>> zipcode.timezone
-6
Upvotes: 5