Ron*_*Ron 10 encoding typeerror google-maps-api-3 geopoints
我有一个数组中的GeoPoints列表,如下所示:
var coordinates = [[50.7, 6.7], [49.5, 7.0], ...]
Run Code Online (Sandbox Code Playgroud)
当我尝试使用这里解释的encodePath
缩小代码时,我收到以下错误:
TypeError:a.lat不是函数
我的代码看起来像这样:
google.maps.geometry.encoding.encodePath(coordinates)
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
Ron*_*Ron 14
最后我找到了解决方案!问题是encodePath
期望一个google.maps.LatLng
对象,而不仅仅是GeoPoints
.
这是一个函数,它将类似上面描述的数组转换为编码字符串:
function encodeLatLngPolygon(array) {
var polyOptions = {
strokeColor: '#000000',
strokeOpacity: 1.0,
strokeWeight: 3
}
poly = new google.maps.Polyline(polyOptions);
var path = poly.getPath();
for(var i=0;i<array.length;i++) {
var xyz = new google.maps.LatLng(parseFloat(array[i][0]).toFixed(2), parseFloat(array[i][1]).toFixed(2));
path.push(xyz);
}
var code = google.maps.geometry.encoding.encodePath(path)
return code;
}
Run Code Online (Sandbox Code Playgroud)
该toFixed
小数点用于保存字节后减少的数量.您可以删除或调整此参数.
归档时间: |
|
查看次数: |
7981 次 |
最近记录: |