简体   繁体   English

从Python到Google Maps实现渐进式可视化?

[英]Implementation progressive visualization from Python to google maps?

I'm mostly working on backend staff, except now in a project I need to use python to do computing and visualize the results on google maps. 我现在主要在后端人员上工作,除了现在在一个项目中,我需要使用python进行计算并在Google地图上可视化结果。 Think about it as, for example, compute the geographical clusters of people tweeting in new york city. 考虑一下它,例如,计算在纽约市发推文的人的地理集群。

In the python program, it runs about 10 seconds, and then output one iteration of data, which is a json object for coordinates. 在python程序中,它运行大约10秒钟,然后输出一个数据迭代,这是一个用于坐标的json对象。 I'm wondering how should I connect this data to google maps? 我想知道如何将这些数据连接到Google地图?

What I thought was let python write data into a file and JS would listen to that file every few milliseconds. 我认为是让python将数据写入文件,而JS会每隔几毫秒监听一次该文件。 However that sounds too hacky. 但是,这听起来太客气了。 Just wondering is there a better way to do it? 只是想知道还有更好的方法吗?

I'm really a newbie to js. 我真的是JS的新手。 please forgive my ignorance. 请原谅我的无知。

Thanks 谢谢

The normal way a HTML page gets data from a backend service (like your coordinate generator every 10 seconds) is to poll a web service (usually, a JSON feed) for updates. HTML页面从后端服务(例如每10秒坐标生成器)获取数据的通常方式是轮询Web服务(通常是JSON feed)以获取更新。

All of the dynamic Google Maps stuff happens within a browser, and that page polls a JSON endpoint, or uses something fancier like websockets to stream data into the browser window. 所有动态Google Maps内容都发生在浏览器中,并且该页面轮询JSON端点,或使用像websockets这样的websockets将数据流式传输到浏览器窗口中。

For the frontend, consider using jQuery , which makes polling JSON dead simple. 对于前端,请考虑使用jQuery ,这使轮询JSON变得非常简单。 Here's some examples. 这是一些例子。

Your "python program" should dump results into a simple database. 您的“ python程序”应将结果转储到简单的数据库中。 While relational and traditional databases like MySQL or PostgreSQL should suffice, i'd encourage you to use a NoSQL database, which handles capped collections . 虽然关系数据库和传统数据库(例如MySQL或PostgreSQL)就足够了,但我还是鼓励您使用NoSQL数据库, 数据库可以处理上限集合 This prevents you from having to clean old data out from a cron schedule. 这样可以避免您必须清除cron计划中的旧数据。 It additionally allows storing data in ranged buckets for some cool playback style histories. 此外,它还允许将数据存储在一定范围的存储桶中,以获取一些很酷的播放样式历史记录。

You should then have a simple web server which can handle the JSON requests from the HTML frontend page, and simply pulls data from the MongoDB. 然后,您应该有一个简单的Web服务器,该服务器可以处理来自HTML前端页面的JSON请求,并且只需从MongoDB中提取数据。 This can be done quickly in any one of the python web frameworks like Flask , Bottle or Pyramid . 可以在FlaskBottlePyramid之类的任何python网络框架中快速完成此操作。 You could also play with something a little sexier like node.js . 您还可以玩一些更性感的东西,例如node.js。 The only requirement here is that a database driver exists for it. 这里唯一的要求是为此存在数据库驱动程序。

Hope that gives a 10,000 foot view of what you need to do now. 希望能给出您现在需要做的10,000英尺的视图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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