【问题标题】:Google Maps API - Geometry Encoding - TypeError: a.lat is not a functionGoogle Maps API - 几何编码 - 类型错误:a.lat 不是函数
【发布时间】:2012-09-04 08:19:47
【问题描述】:

我在一个数组中有一个 GeoPoints 列表,如下所示:

var coordinates = [[50.7, 6.7], [49.5, 7.0], ...]

当我尝试使用encodePath 将代码缩小为explained here 时,我收到以下错误:

TypeError: a.lat 不是函数

我的代码如下所示:

google.maps.geometry.encoding.encodePath(coordinates)

有什么想法吗?

【问题讨论】:

    标签: encoding google-maps-api-3 typeerror geopoints


    【解决方案1】:

    我终于找到了解决方案!问题是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;
    }
    

    toFixed 减少小数点后的数字以节省字节。您可以删除或调整此参数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-01-12
      • 1970-01-01
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-02
      相关资源
      最近更新 更多