简体   繁体   中英

Good Python library for plotting points on a U.S. map by zip code

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 US 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.)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM