【发布时间】:2017-03-12 14:25:44
【问题描述】:
当我绘制几何图形时,我想在边界内添加几何标签,并将站点添加到谷歌地图上 geojson 层边界的中心。
map.data.addListener("addfeature", function(feature){
var g=feature.getGeometry();
console.log("test ok");
//var bounds = new google.maps.LatLngBounds();
console.log(g.get());
return feature;
});
我根据 google 开发参考 (https://developers.google.com/maps/documentation/javascript/reference#Data) 添加带有监听器 addfeature 的 map.data
根据page(https://developers.google.com/maps/documentation/javascript/reference#Data.AddFeatureEvent),函数catch up addfeature listener with argument应该是feature object。
根据要素类页面(https://developers.google.com/maps/documentation/javascript/reference#Data.Feature),要素对象应该有getGeometry()方法。
但是当我执行上面的代码时,我从浏览器中得到一个错误。
Uncaught TypeError: feature.getGeometry is not a function
at He.<anonymous> (bakb.html:37)
at qe._.y.trigger (js?sensor=true&callback=myMap:104)
at qe.<anonymous> (js?sensor=true&callback=myMap:38)
at Object._.y.trigger (js?sensor=true&callback=myMap:104)
at qe._.k.add (js?sensor=true&callback=myMap:116)
at js?sensor=true&callback=myMap:69
at Object._.ab (js?sensor=true&callback=myMap:35)
at Object._.re (js?sensor=true&callback=myMap:69)
at Ub (data.js:11)
at OF (util.js:136)
我通过以下方式调用google map api:
<script src="//maps.google.com/maps/api/js?sensor=true&callback=myMap></script>
我认为我正确使用了谷歌地图。 但是为什么没有定义 feature.getGeometry 方法呢? 如何从特征中获取几何?回调函数中的特征争论真的是特征对象吗?如果不是如何从争论中获取几何?
【问题讨论】:
标签: javascript google-maps google-maps-api-3 gis geojson