首页 > 解决方案 > 谷歌表格脚本无法识别拆分功能

问题描述

这是我的代码。由于某种原因,Sheets 说“无法识别拆分功能”。

function distance3(latlon1, latlon2){
  var [lat1, lon1] = split(latlon1,",");
  var [lat2, lon2] = split(latlon2,",");
  var R = 6371000; // radius of the earth in meters, https://en.wikipedia.org/wiki/Earth_radius
  var dLat = (lat2-lat1) * Math.PI / 180; // Convert degrees to radians
  var dLon = (lon2-lon1) * Math.PI / 180; // Convert degrees to radians
  var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
          Math.cos(lat1 * Math.PI / 180 ) * Math.cos(lat2 * Math.PI / 180 ) *
          Math.sin(dLon/2) * Math.sin(dLon/2);
  var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c;

  // Distance in meters, rounded to an integer.
  return Math.round(d)*0.000621371;
}

谢谢你!

标签: google-apps-scriptgoogle-sheetssplit

解决方案


尝试:

var [lat1, lon1] = latlon1.split(",");

推荐阅读