首页 > 解决方案 > turf.js 返回无效坐标

问题描述

此代码是一个程序的一部分,该程序接收用户在搜索栏中输入的地址并尝试在地图上找到它们。这是该网站的链接。

createSQL: function() {
    SearchableMapLib.currentPinpoint = [results[0].geometry.location.lat(), results[0].geometry.location.lng()];
    var address = $("#search-address").val();
    SearchableMapLib.currentResults = JSON.parse(JSON.stringify(SearchableMapLib.geojsonData));
    
    if(SearchableMapLib.currentPinpoint != null && address != '') {           
        var point = turf.point([SearchableMapLib.currentPinpoint[1], SearchableMapLib.currentPinpoint[0]]);             
        var buffered = turf.buffer(point, SearchableMapLib.radius, {units: 'meters'});
        
        ///it breaks here at turf.pointsWithinPolygon
        SearchableMapLib.currentResults = turf.pointsWithinPolygon(SearchableMapLib.currentResults, buffered);
        
        if (SearchableMapLib.debug) {
          console.log('found points within')
          console.log(SearchableMapLib.currentResults);
        }

但是,它告诉我“未捕获的错误:没有有效的坐标”。

我很确定坐标是有效的。例如,当我输入console.log('point: ' + SearchableMapLib.currentPinpoint[1] + ' ' + SearchableMapLib.currentPinpoint[0]);它返回point: -83.6235566 42.24362170000001

为什么会发生此错误?

(我是 javascript 新手,没有编写此代码(它基于模板),如果其中任何一个没有意义,请告诉我。)

标签: javascriptleafletturfjs

解决方案


也许纬度和经度是相反的?一个在南极洲,另一个在底特律附近。


推荐阅读