【发布时间】:2017-12-21 11:12:47
【问题描述】:
我正在尝试将 GeoJson 文件嵌入谷歌地图 api,但它没有向我显示地图上的 json 文件。地图是空的。 我已将 json 文件放在我的 Windows 服务器上(使用 iis) 还有我用notepad++写的html页面
这是代码:
<!DOCTYPE html>
<html>
<head>
<style>
#map {
height: 400px;
width: 100%;
}
marker{
color:green;
}
</style>
</head>
<body>
<h3>My Google Maps Demo PLIZZZZZZZZZZZZZ</h3>
<div id="map"></div>
<script>
function initMap() {
var uluru = {lat: -25.363, lng: 131.044};
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 4,
center: uluru
});
// NOTE: This uses cross-domain XHR, and may not work on older browsers.
map.data.loadGeoJson(
'D:/Program Files (x86)/Notepad++googlejson.json');
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAYTSB-wjOrjVjPGazmGeGCLzUxKa_gmA8&libraries=places&callback=initMap">
</script>
</body>
</html>
json文件
看起来像这样:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"letter": "G",
"color": "blue",
"rank": "7",
"ascii": "71"
},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[123.61, -22.14], [122.38, -21.73], [121.06, -21.69], [119.66, -22.22], [119.00, -23.40],
[118.65, -24.76], [118.43, -26.07], [118.78, -27.56], [119.22, -28.57], [120.23, -29.49],
[121.77, -29.87], [123.57, -29.64], [124.45, -29.03], [124.71, -27.95], [124.80, -26.70],
[124.80, -25.60], [123.61, -25.64], [122.56, -25.64], [121.72, -25.72], [121.81, -26.62],
[121.86, -26.98], [122.60, -26.90], [123.57, -27.05], [123.57, -27.68], [123.35, -28.18],
[122.51, -28.38], [121.77, -28.26], [121.02, -27.91], [120.49, -27.21], [120.14, -26.50],
[120.10, -25.64], [120.27, -24.52], [120.67, -23.68], [121.72, -23.32], [122.43, -23.48],
[123.04, -24.04], [124.54, -24.28], [124.58, -23.20], [123.61, -22.14]
]
]
}
}
]
}
更新 - 我也尝试将 json 文件放在我的电脑上,但仍然不行
【问题讨论】:
-
您的网络服务器不工作。 (
GET http://vmedu140.mtacloud.co.il/googlejson.json net::ERR_CONNECTION_TIMED_OUT) -
你确定吗?因为当我输入这个地址时 - vmedu140.mtacloud.co.il/googlejson.json
-
不适合我,我都得到
This site can’t be reached vmedu140.mtacloud.co.il took too long to respond.。 -
如果我在本地计算机上尝试:map.data.loadGeoJson('D:/Program Files (x86)/Notepad++googlejson.json');它不工作
-
你的 javascript 控制台说什么?
标签: javascript json google-maps google-maps-api-3 geojson