简体   繁体   English

从基于 Google 表格的列表中获取最接近的坐标

[英]Get closest coördinates from a list based in Google Sheets

I have seen a similar question here, but that answer did not to the job for me yet.我在这里看到了一个类似的问题,但这个答案还没有适合我的工作。 We have a Google Sheets doc with 46 adresses, and converted longitude and latitude from that location.我们有一个包含 46 个地址的 Google 表格文档,并从该位置转换了经度和纬度。

Now we would like to be able to give in a location, from which we also get the longitude and latitude and for which we find the closest address based on the coördinates in the list.现在我们希望能够提供一个位置,从中我们还可以获得经度和纬度,并根据列表中的坐标找到最近的地址。

Our document is here: https://docs.google.com/spreadsheets/d/1fKBGbRlOX6gw77Nk0S_9ZmsJ-fefM4mA_Ys-Mu-QHIA/edit?usp=sharing我们的文档在这里: https://docs.google.com/spreadsheets/d/1fKBGbRlOX6gw77Nk0S_9ZmsJ-fefM4mA_Ys-Mu-QHIA/edit?usp=sharing

In this file the addresses are shown in Column A, the longitude in column B and the latitude in column C. In Column E we will enter the location and in column F and G the longitude and latitude will be shown.在此文件中,地址显示在 A 列中,经度显示在 B 列中,纬度显示在 C 列中。在 E 列中,我们将输入位置,在 F 和 G 列中显示经度和纬度。 Now in column H it should show the nearest location from the list in Column A.现在在 H 列中,它应该显示与 A 列中的列表最近的位置。

We have tried:我们尝试过:

ZOEKEN(1;1/INTERVAL(0;SIN((RADIALEN(B$2:B$47-F2))/2)^2+SIN((RADIALEN(C$2:C$47-G2))/2)^2*COS(RADIALEN(B$2:B$47))*COS(RADIALEN(G2)));A$2:A$47)

But the location it gives is not the closest upon checking in Google Maps.但是它给出的位置在谷歌地图上并不是最近的。

Anyone able to help?有人能帮忙吗?

To get the real driving or commuting distances between two addresses, use the GoogleMapsDistance custom function. Note that a driving distance is different from a bee line distance.要获得两个地址之间的实际驾驶或通勤距离,请使用GoogleMapsDistance自定义 function。请注意,驾驶距离不同于蜜蜂线距离。 Your existing formula appears to calculate the latter:您现有的公式似乎可以计算后者:

=LOOKUP(1;1/FREQUENCY(0;SIN((RADIANS(B$2:B$47-F2))/2)^2+SIN((RADIANS(C$2:C$47-G2))/2)^2*COS(RADIANS(B$2:B$47))*COS(RADIANS(G2)));A$2:A$47)

The formula seems overly complex.公式似乎过于复杂。 When you are dealing with distances of max a couple hundred kilometers, you can use the Pythagorean theorem instead:当您处理最大几百公里的距离时,您可以改用毕达哥拉斯定理

distance² = (startLat - endLat)² + (startLong - endLong)²

A trickier problem is that the custom function you are using does not return numeric latitudes and longitudes.一个更棘手的问题是您使用的自定义 function 不返回数字纬度和经度。 It returns text strings that use period as the decimal mark.它返回使用句点作为小数点的文本字符串。 Your spreadsheet's locale does not use periods but commas as decimal mark.您的电子表格的区域设置不使用句点,而是使用逗号作为小数点。 You should replace those periods with commas with substitute() , like this:您应该使用substitute()将这些句号替换为逗号,如下所示:

=arrayformula( 
  lambda( 
    addressStart; latStart; longStart; latEnd; longEnd; 
    map( 
      latEnd; longEnd; 
      lambda( 
        latThis; longThis; 
        if( 
          latThis * longThis;
          sortn( 
            { addressStart \ sqrt( (latStart - latThis) ^ 2 + (longStart - longThis) ^ 2 ) }; 
            1; 0; 2; true 
          ); 
          iferror(1/0) 
        ) 
      ) 
    ) 
  )( 
    A2:A; 
    substitute(B2:B; "."; ","); 
    substitute(C2:C; "."; ","); 
    substitute(F2:F10; "."; ","); 
    substitute(G2:G10; "."; ",") 
  ) 
)

See your sample spreadsheet .请参阅您的示例电子表格

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何根据下拉列表选择从谷歌表格中获取信息? - How to get info from google sheets based on drop list selection? Google Sheets:从最接近第一个四分位数的数据中获取值 - Google Sheets: get the value from data closest to the first quartile Google 表格获取值匹配最近的日期 - Google Sheets Get The Value Matching Closest Date 如何从 Google 表格中不断增长的字符串列表中找到与字符串最接近的匹配项? - How to find the closest match to a string from ever-growing list of strings in Google sheets? 如何根据另一个工作表中的列表过滤行? (Google表格) - How To Filter Rows Based On A List From Another Sheet? (Google Sheets) 如何基于带有Google表格数据的模板获取HTML代码 - How to get HTML code, based on a template with data from Google Sheets (Google 表格)根据行信息从另一个电子表格中获取价值 - (Google Sheets) Get Value from Another Spreadsheet Based On Row Info Google 表格 - 基于标准的列表中的最佳组合 - Google Sheets - best combination from list based on criteria 你如何从谷歌表格中的表格中获取数据列表? - How do you get a list of data from a table in google sheets? 从列表中获取 Google 表格中的平均股票价格 - Get average stock price in Google Sheets from a list
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM