【发布时间】:2018-03-12 14:47:46
【问题描述】:
我在为 google maps api 找出标签时遇到了一些麻烦。我正在调用我的 geojson 并像这样加载我的地图:
var map;
function init() {
map = new google.maps.Map(document.getElementById('map'), {
zoom: 11,
center: {lat: 43.2, lng: -84.65},
mapTypeId: google.maps.MapTypeId.ROADMAP
});
map.data.loadGeoJson(
'Maps/Newark.geojson');
map.data.setStyle({
icon: {
path: google.maps.SymbolPath.CIRCLE,
scale: 4,
fillColor: 'blue',
fillOpacity: .5,
strokeColor: 'blue',
strokeWeight: 1
}
})
}
这是示例 geojson 数据:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ -84.69729,43.24808 ]
},
"properties": {
"Name":"Name 1",
"Address":"My Address",
"City":"town",
"State":"ST",
"Zip":12345,
"Group":"Newark"
}
},
{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates": [ -84.58872,43.23395 ]
},
"properties": {
"Name":"Name 2",
"Address":"another address",
"City":"town",
"State":"ST",
"Zip": 12345,
"Group":"Newark"
}
}
]
}
我想要做的是将属性命名为标记的标签。
我尝试了this,但无法成功。
【问题讨论】:
-
你能弄清楚如何为 geoJson 标记显示标签吗?
-
是的,我使用了下面的答案。
标签: google-maps-api-3 label geojson