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

こ雲淡風輕ζ 提交于 2020-01-11 10:02:28

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/16388743/good-python-library-for-plotting-points-on-a-u-s-map-by-zip-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!