将JSON文件中的数据可视化到Google地图上。

huangapple go评论77阅读模式
英文:

Visualize data from json file to google maps

问题

我有一个来自Google Sheets API的JSON格式文件。我需要标记JSON文件中的地址,并在单击标记的地址时显示工作完成百分比。我知道可以在地图上显示数据,但我需要地图上的数据实时更新(与Google表格数据同步)。

示例JSON:

[{"STAGES/ /JOB LIST":"JOB 1","ADDRESS":"4 Talbot Drive","CITY/ STATE/ ZIP CODE":"Panorama City, CA 91402","STAGE 1":"COMPLETED","STAGE 2":"COMPLETED","STAGE 3":"COMPLETED","STAGE 4":"COMPLETED","STAGE 5":"COMPLETED","STAGE 6":"COMPLETED","STAGE 7":"COMPLETED","STAGE 8":"COMPLETED","STAGE 9":"COMPLETED","STAGE 10":"COMPLETED","TOTAL PROGRESS":1,"":0},
...
{"STAGES/ /JOB LIST":"JOB 10","ADDRESS":"46 Van Dyke Dr.","CITY/ STATE/ ZIP CODE":"San Jose, CA 95123","STAGE 1":"IN PROGRESS","STAGE 2":"COMPLETED","STAGE 3":"PENDING","STAGE 4":"PENDING","STAGE 5":"PENDING","STAGE 6":"PENDING","STAGE 7":"PENDING","STAGE 8":"PENDING","STAGE 9":"PENDING","STAGE 10":"PENDING","TOTAL PROGRESS":0.1,"":1},{"STAGES/ /JOB LIST":"PROGRESS ON THIS STAGE","ADDRESS":"","CITY/ STATE/ ZIP CODE":"","STAGE 1":0.9,"STAGE 2":0.9,"STAGE 3":0.8,"STAGE 4":0.7000000000000001,"STAGE 5":0.5,"STAGE 6":0.4,"STAGE 7":0.30000000000000004,"STAGE 8":0.2,"STAGE 9":0.1,"STAGE 10":0.2,"TOTAL PROGRESS":0.5,"":9},{"STAGES/ /JOB LIST":"","ADDRESS":"","CITY/ STATE/ ZIP CODE":"","STAGE 1":"","STAGE 2":"","STAGE 3":"","STAGE 4":"","STAGE 5":"","STAGE 6":"","STAGE 7":"","STAGE 8":"","STAGE 9":"","STAGE 10":"","TOTAL PROGRESS":"","":""}]

感谢您的帮助。

英文:

I have a JSON format file from Google sheets API. I need to mark the addresses in the JSON file and display the percentage of job completion when you click on the marked address. I know I can display the data on the map, but I need the data on the map to be updated in real-time (sync with Google sheet data).

Sample JSON:

> [{"STAGES/ /JOB LIST":"JOB 1","ADDRESS":"4 Talbot Drive","CITY/ STATE/ ZIP CODE":"Panorama City, CA 91402","STAGE 1":"COMPLETED","STAGE 2":"COMPLETED","STAGE 3":"COMPLETED","STAGE 4":"COMPLETED","STAGE 5":"COMPLETED","STAGE 6":"COMPLETED","STAGE 7":"COMPLETED","STAGE 8":"COMPLETED","STAGE 9":"COMPLETED","STAGE 10":"COMPLETED","TOTAL PROGRESS":1,"":0},
......
{"STAGES/ /JOB LIST":"JOB 10","ADDRESS":"46 Van Dyke Dr.","CITY/ STATE/ ZIP CODE":"San Jose, CA 95123","STAGE 1":"IN PROGRESS","STAGE 2":"COMPLETED","STAGE 3":"PENDING","STAGE 4":"PENDING","STAGE 5":"PENDING","STAGE 6":"PENDING","STAGE 7":"PENDING","STAGE 8":"PENDING","STAGE 9":"PENDING","STAGE 10":"PENDING","TOTAL PROGRESS":0.1,"":1},{"STAGES/ /JOB LIST":"PROGRESS ON THIS STAGE","ADDRESS":"","CITY/ STATE/ ZIP CODE":"","STAGE 1":0.9,"STAGE 2":0.9,"STAGE 3":0.8,"STAGE 4":0.7000000000000001,"STAGE 5":0.5,"STAGE 6":0.4,"STAGE 7":0.30000000000000004,"STAGE 8":0.2,"STAGE 9":0.1,"STAGE 10":0.2,"TOTAL PROGRESS":0.5,"":9},{"STAGES/ /JOB LIST":"","ADDRESS":"","CITY/ STATE/ ZIP CODE":"","STAGE 1":"","STAGE 2":"","STAGE 3":"","STAGE 4":"","STAGE 5":"","STAGE 6":"","STAGE 7":"","STAGE 8":"","STAGE 9":"","STAGE 10":"","TOTAL PROGRESS":"","":""}]

Appreciate your help.

答案1

得分: -1

为了在地图上标记地址并在点击时显示工作完成百分比,您可以使用Google Maps API和实时数据同步机制的组合。以下是涉及的步骤的高级概述:

  1. 获取API密钥:从Google Cloud控制台获取API密钥以访问Google Maps API。

  2. 设置地图:使用HTML、CSS和JavaScript创建一个可以显示地图的网页或应用程序。

  3. 集成Google Maps API:使用Maps JavaScript API将地图嵌入到您的网页上,并为地址显示标记。

  4. 获取和处理JSON数据:从Google Sheets API检索JSON数据并在您的应用程序中解析它。

  5. 地理编码地址:使用地理编码服务,如Google Geocoding API,将地址转换为用于在地图上放置标记的纬度和经度坐标。

  6. 更新地图标记:当您获取新数据或从Google Sheets API接收更新时,相应地更新地图上的标记。

  7. 计算工作完成百分比:根据您拥有的数据确定工作完成百分比,并将其与每个标记关联。

  8. 添加点击事件侦听器:将点击事件侦听器附加到地图上的标记。当点击标记时,显示相应的地址和工作完成百分比。

  9. 实时数据同步:要实时同步Google Sheets数据,您有几种选项。一种方法是使用Google Sheets API的“推送”功能,您的应用程序订阅更新并在表格数据更改时收到通知。然后,您可以相应地更新地图标记。

  10. 持续更新地图数据:实施一种机制,如轮询或WebSocket连接,以定期从Google Sheets API获取最新数据并相应地更新地图标记。

通过遵循这些步骤,您可以创建一个动态地图,显示地址、工作完成百分比,并与Google Sheets数据实时同步。请记得安全处理访问Google Sheets和Maps API的任何身份验证和授权要求。

英文:

To mark addresses on a map and display the percentage of job completion when clicked, you can use a combination of Google Maps API and a mechanism to sync the data in real-time. Here's a high-level overview of the steps involved:

Obtain an API key: Get an API key from the Google Cloud Console to access the Google Maps API.

Set up a map: Create a web page or application where you can display the map using HTML, CSS, and JavaScript.

Integrate the Google Maps API: Use the Maps JavaScript API to embed the map on your web page and display markers for the addresses.

Fetch and process the JSON data: Retrieve the JSON data from the Google Sheets API and parse it in your application.

Geocode addresses: Use a geocoding service, such as the Google Geocoding API, to convert the addresses into latitude and longitude coordinates for placing markers on the map.

Update map markers: As you fetch new data or receive updates from the Google Sheets API, update the markers on the map accordingly.

Calculate job completion percentage: Determine the percentage of job completion based on the data you have, and associate it with each marker.

Add click event listeners: Attach click event listeners to the markers on the map. When a marker is clicked, display the corresponding address and job completion percentage.

Real-time data sync: To sync the Google Sheets data in real-time, you have a few options. One approach is to use the Google Sheets API's "Push" functionality, where your application subscribes to updates and receives notifications whenever the sheet data changes. You can then update the map markers accordingly.

Continuously update map data: Implement a mechanism, such as polling or WebSocket connections, to periodically fetch the latest data from the Google Sheets API and update the map markers accordingly.

By following these steps, you can create a dynamic map that displays the addresses, job completion percentage, and syncs with the Google Sheets data in real-time. Remember to handle any authentication and authorization requirements for accessing the Google Sheets and Maps APIs securely.

huangapple
  • 本文由 发表于 2023年7月18日 14:01:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/76709883.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定