【发布时间】:2020-04-13 11:40:42
【问题描述】:
由于 Google Fusion Tables 已关闭,我正在尝试使用 JSON 文件重新创建数据层(包含美国县)。
这是我的 JS:
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
//center on the US
center: {lat: 39.8283, lng: -98.5795},
zoom: 5
});
var script = document.createElement('script');
//call json file of US counties
script.src = 'assets/sheet/places.json';
document.getElementsByTagName('head')[0].appendChild(script);
}
</script>
当我运行页面时,地图可以工作,但我收到一条错误消息:“Uncaught SyntaxError: Unexpected token ':'”仅在 JSON 文件的第二行。
有谁知道我可以做些什么来解决这个问题?我浏览了 Google 的页面,但无法找到解决方案。仅供参考,我基本上没有使用 JSON 的经验,但还没有找到另一种使用 Google Maps API 轻松传达大型数据集的方法。
JSON 文件在这里,如果有人想看的话:https://www.estherloui.se/projects/sheet/gz_2010_us_050_00_20m.json
【问题讨论】:
-
这能回答你的问题吗? Load local JSON file into variable
标签: javascript json google-maps google-maps-api-3 geojson