找回密码
 立即注册

QQ登录

只需一步,快速开始

houys 悬赏达人认证 活字格认证

高级会员

133

主题

443

帖子

1582

积分

高级会员

积分
1582

活字格高级认证悬赏达人活字格认证圣诞拼拼乐

houys 悬赏达人认证 活字格认证
高级会员   /  发表于:2020-5-22 16:11  /   查看:1700  /  回复:7
1金币
本帖最后由 houys 于 2020-5-26 14:46 编辑

Uncaught SyntaxError: Unexpected token 'export'
  这个怎么解决,网上有说引用js文件时需要设置<script  src"" type="module">
  如果可以的话这个怎么设置,或者怎么解决这个不能使用export的问题呢

还有就是直接调用全局js的话直接用方法名就可以了吗?

附件: 您需要 登录 才可以下载或查看,没有帐号?立即注册

7 个回复

正序浏览
houys悬赏达人认证 活字格认证
高级会员   /  发表于:2020-5-25 11:42:16
8#
本帖最后由 houys 于 2020-5-25 15:01 编辑

在后端定义了方法重写了一遍里面的算法,谢谢。
回复 使用道具 举报
谢厅讲师达人认证 悬赏达人认证 活字格认证
金牌服务用户   /  发表于:2020-5-23 22:05:45
7#

按照我粗浅的理解,这应该是后端代码吧
回复 使用道具 举报
谢厅讲师达人认证 悬赏达人认证 活字格认证
金牌服务用户   /  发表于:2020-5-23 19:07:03
6#
本帖最后由 谢厅 于 2020-5-23 19:08 编辑
houys 发表于 2020-5-23 17:01
直接写括号的话编译时报错,错误为:应为声明或语句。
原来的那个错误你们使用export时会报错吗,如果不会 ...

上工程文件吧
回复 使用道具 举报
houys悬赏达人认证 活字格认证
高级会员   /  发表于:2020-5-23 17:01:57
地板
直接写括号的话编译时报错,错误为:应为声明或语句。
原来的那个错误你们使用export时会报错吗,如果不会的话我再看看代码。如果说正常使用export也报错是不是就是需要设置一些东西
回复 使用道具 举报
谢厅讲师达人认证 悬赏达人认证 活字格认证
金牌服务用户   /  发表于:2020-5-23 12:19:39
板凳

不太清楚这个SDK的使用规则,不过我感觉最后这个应该用export(GPS);
回复 使用道具 举报
houys悬赏达人认证 活字格认证
高级会员   /  发表于:2020-5-23 11:11:51
沙发
本帖最后由 houys 于 2020-5-23 11:15 编辑
  1. var GPS = {
  2.   PI: 3.14159265358979324,
  3.   x_pi: (3.14159265358979324 * 3000.0) / 180.0,
  4.   a: 6378245.0, //  a: 卫星椭球坐标投影到平面地图坐标系的投影因子。
  5.   ee: 0.00669342162296594323, //  ee: 椭球的偏心率。
  6.   delta: function (lat, lon) {
  7.     // Krasovsky 1940
  8.     //
  9.     // a = 6378245.0, 1/f = 298.3
  10.     // b = a * (1 - f)
  11.     // ee = (a^2 - b^2) / a^2;

  12.     if (this.outOfChina(lat, lon)) {
  13.       return {
  14.         lat: lat,
  15.         lon: lon
  16.       }
  17.     }
  18. //以下都是算法和方法。输出在最底下
  19.     var dLat = this.transformLat(lon - 105.0, lat - 35.0)
  20.     var dLon = this.transformLon(lon - 105.0, lat - 35.0)
  21.     var radLat = (lat / 180.0) * this.PI
  22.     var magic = Math.sin(radLat)
  23.     magic = 1 - this.ee * magic * magic
  24.     var sqrtMagic = Math.sqrt(magic)
  25.     dLat =
  26.       (dLat * 180.0) /
  27.       (((this.a * (1 - this.ee)) / (magic * sqrtMagic)) * this.PI)
  28.     dLon = (dLon * 180.0) / ((this.a / sqrtMagic) * Math.cos(radLat) * this.PI)
  29.     lat = lat + dLat
  30.     lon = lon + dLon
  31.     return {
  32.       lat: lat,
  33.       lon: lon
  34.     }
  35.   },
  36.   deltaOut: function (lat, lon) {
  37.     // Krasovsky 1940
  38.     //
  39.     // a = 6378245.0, 1/f = 298.3
  40.     // b = a * (1 - f)
  41.     // ee = (a^2 - b^2) / a^2;

  42.     if (this.outOfChina(lat, lon)) {
  43.       return {
  44.         lat: lat,
  45.         lon: lon
  46.       }
  47.     }

  48.     var dLat = this.transformLat(lon - 105.0, lat - 35.0)
  49.     var dLon = this.transformLon(lon - 105.0, lat - 35.0)
  50.     var radLat = (lat / 180.0) * this.PI
  51.     var magic = Math.sin(radLat)
  52.     magic = 1 - this.ee * magic * magic
  53.     var sqrtMagic = Math.sqrt(magic)
  54.     dLat =
  55.       (dLat * 180.0) /
  56.       (((this.a * (1 - this.ee)) / (magic * sqrtMagic)) * this.PI)
  57.     dLon = (dLon * 180.0) / ((this.a / sqrtMagic) * Math.cos(radLat) * this.PI)
  58.     lat = lat - dLat
  59.     lon = lon - dLon
  60.     return {
  61.       lat: lat,
  62.       lon: lon
  63.     }
  64.   },

  65.   // WGS-84 to GCJ-02
  66.   gcj_encrypt: function (wgsLat, wgsLon) {
  67.     var d = this.delta(wgsLat, wgsLon)

  68.     return {
  69.       lat: d.lat,
  70.       lon: d.lon
  71.     }
  72.   },
  73.   // GCJ-02 to WGS-84
  74.   gcj_decrypt: function (gcjLat, gcjLon) {
  75.     if (this.outOfChina(gcjLat, gcjLon)) {
  76.       return {
  77.         lat: gcjLat,
  78.         lon: gcjLon
  79.       }
  80.     }

  81.     var d = this.delta(gcjLat, gcjLon)
  82.     return {
  83.       lat: gcjLat - d.lat,
  84.       lon: gcjLon - d.lon
  85.     }
  86.   },
  87.   // GCJ-02 to WGS-84 exactly
  88.   gcj_decrypt_exact: function (gcjLat, gcjLon) {
  89.     var initDelta = 0.01
  90.     var threshold = 0.000000001
  91.     var dLat = initDelta,
  92.       dLon = initDelta
  93.     var mLat = gcjLat - dLat,
  94.       mLon = gcjLon - dLon
  95.     var pLat = gcjLat + dLat,
  96.       pLon = gcjLon + dLon
  97.     var wgsLat,
  98.       wgsLon,
  99.       i = 0
  100.     while (1) {
  101.       wgsLat = (mLat + pLat) / 2
  102.       wgsLon = (mLon + pLon) / 2
  103.       var tmp = this.gcj_encrypt(wgsLat, wgsLon)
  104.       dLat = tmp.lat - gcjLat
  105.       dLon = tmp.lon - gcjLon
  106.       if (Math.abs(dLat) < threshold && Math.abs(dLon) < threshold) {
  107.         break
  108.       }

  109.       if (dLat > 0) pLat = wgsLat
  110.       else mLat = wgsLat
  111.       if (dLon > 0) pLon = wgsLon
  112.       else mLon = wgsLon

  113.       if (++i > 10000) break
  114.     }
  115.     // console.log(i);
  116.     return {
  117.       lat: wgsLat,
  118.       lon: wgsLon
  119.     }
  120.   },
  121.   // GCJ-02 to BD-09
  122.   bd_encrypt: function (gcjLat, gcjLon) {
  123.     var x = gcjLon,
  124.       y = gcjLat
  125.     var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * this.x_pi)
  126.     var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * this.x_pi)
  127.     var bdLon = z * Math.cos(theta) + 0.0065
  128.     var bdLat = z * Math.sin(theta) + 0.006
  129.     return {
  130.       lat: bdLat,
  131.       lon: bdLon
  132.     }
  133.   },
  134.   // BD-09 to GCJ-02
  135.   bd_decrypt: function (bdLat, bdLon) {
  136.     var x = bdLon - 0.0065,
  137.       y = bdLat - 0.006
  138.     var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * this.x_pi)
  139.     var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * this.x_pi)
  140.     var gcjLon = z * Math.cos(theta)
  141.     var gcjLat = z * Math.sin(theta)
  142.     return {
  143.       lat: gcjLat,
  144.       lon: gcjLon
  145.     }
  146.   },
  147.   // WGS-84 to Web mercator
  148.   // mercatorLat -> y mercatorLon -> x
  149.   mercator_encrypt: function (wgsLat, wgsLon) {
  150.     var x = (wgsLon * 20037508.34) / 180.0
  151.     var y =
  152.       Math.log(Math.tan(((90.0 + wgsLat) * this.PI) / 360.0)) /
  153.       (this.PI / 180.0)
  154.     y = (y * 20037508.34) / 180.0
  155.     return {
  156.       lat: y,
  157.       lon: x
  158.     }
  159.   },
  160.   // Web mercator to WGS-84
  161.   // mercatorLat -> y mercatorLon -> x
  162.   mercator_decrypt: function (mercatorLat, mercatorLon) {
  163.     var x = (mercatorLon / 20037508.34) * 180.0
  164.     var y = (mercatorLat / 20037508.34) * 180.0
  165.     y =
  166.       (180 / this.PI) *
  167.       (2 * Math.atan(Math.exp((y * this.PI) / 180.0)) - this.PI / 2)
  168.     return {
  169.       lat: y,
  170.       lon: x
  171.     }
  172.   },
  173.   // two point's distance
  174.   distance: function (latA, lonA, latB, lonB) {
  175.     var earthR = 6371000.0
  176.     var x =
  177.       Math.cos((latA * this.PI) / 180.0) *
  178.       Math.cos((latB * this.PI) / 180.0) *
  179.       Math.cos(((lonA - lonB) * this.PI) / 180)
  180.     var y =
  181.       Math.sin((latA * this.PI) / 180.0) * Math.sin((latB * this.PI) / 180.0)
  182.     var s = x + y
  183.     if (s > 1) s = 1
  184.     if (s < -1) s = -1
  185.     var alpha = Math.acos(s)
  186.     var distance = alpha * earthR
  187.     return distance
  188.   },
  189.   outOfChina: function (lat, lon) {
  190.     if (lon < 72.004 || lon > 137.8347) {
  191.       return true
  192.     }
  193.     if (lat < 0.8293 || lat > 55.8271) {
  194.       return true
  195.     }
  196.     return false
  197.   },
  198.   transformLat: function (x, y) {
  199.     var ret = -100.0 +
  200.       2.0 * x +
  201.       3.0 * y +
  202.       0.2 * y * y +
  203.       0.1 * x * y +
  204.       0.2 * Math.sqrt(Math.abs(x))
  205.     ret +=
  206.       ((20.0 * Math.sin(6.0 * x * this.PI) +
  207.           20.0 * Math.sin(2.0 * x * this.PI)) *
  208.         2.0) /
  209.       3.0
  210.     ret +=
  211.       ((20.0 * Math.sin(y * this.PI) + 40.0 * Math.sin((y / 3.0) * this.PI)) *
  212.         2.0) /
  213.       3.0
  214.     ret +=
  215.       ((160.0 * Math.sin((y / 12.0) * this.PI) +
  216.           320 * Math.sin((y * this.PI) / 30.0)) *
  217.         2.0) /
  218.       3.0
  219.     return ret
  220.   },
  221.   transformLon: function (x, y) {
  222.     var ret =
  223.       300.0 +
  224.       x +
  225.       2.0 * y +
  226.       0.1 * x * x +
  227.       0.1 * x * y +
  228.       0.1 * Math.sqrt(Math.abs(x))
  229.     ret +=
  230.       ((20.0 * Math.sin(6.0 * x * this.PI) +
  231.           20.0 * Math.sin(2.0 * x * this.PI)) *
  232.         2.0) /
  233.       3.0
  234.     ret +=
  235.       ((20.0 * Math.sin(x * this.PI) + 40.0 * Math.sin((x / 3.0) * this.PI)) *
  236.         2.0) /
  237.       3.0
  238.     ret +=
  239.       ((150.0 * Math.sin((x / 12.0) * this.PI) +
  240.           300.0 * Math.sin((x / 30.0) * this.PI)) *
  241.         2.0) /
  242.       3.0
  243.     return ret
  244.   }
  245. }

  246. /**
  247. * @desc   时间格式化
  248. * @param  {String} fmt  default: 'yyyy-MM-dd hh:mm:ss'
  249. * @return {String}
  250. */
  251. Date.prototype.Format = function (fmt) {
  252.   if ((fmt == null) | (fmt == '')) {
  253.     fmt = 'yyyy-MM-dd hh:mm:ss'
  254.   }
  255.   var o = {
  256.     'M+': this.getMonth() + 1, // 月份
  257.     'd+': this.getDate(), // 日
  258.     'h+': this.getHours(), // 小时
  259.     'm+': this.getMinutes(), // 分
  260.     's+': this.getSeconds(), // 秒
  261.     'q+': Math.floor((this.getMonth() + 3) / 3), // 季度
  262.     S: this.getMilliseconds() // 毫秒
  263.   }
  264.   if (/(y+)/.test(fmt)) {
  265.     fmt = fmt.replace(
  266.       RegExp.$1,
  267.       (this.getFullYear() + '').substr(4 - RegExp.$1.length)
  268.     )
  269.   }
  270.   for (var k in o) {
  271.     if (new RegExp('(' + k + ')').test(fmt)) {
  272.       fmt = fmt.replace(
  273.         RegExp.$1,
  274.         RegExp.$1.length == 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
  275.       )
  276.     }
  277.   }

  278.   return fmt.replace(/\//g, '-')
  279. }

  280. /**
  281. * @desc  移除元素
  282. * @param {Number} dx
  283. */
  284. Array.prototype.remove = function (dx) {
  285.   if (isNaN(dx) || dx > this.length) {
  286.     return false
  287.   }
  288.   for (var i = 0, n = 0; i < this.length; i++) {
  289.     if (this[i] != this[dx]) {
  290.       this[n++] = this[i]
  291.     }
  292.   }
  293.   this.length -= 1
  294. }

  295. /**
  296. * @desc  数组去重
  297. */
  298. Array.prototype.unique = function () {
  299.   var res = [this[0]]
  300.   for (var i = 1; i < this.length; i++) {
  301.     var repeat = false
  302.     for (var j = 0; j < res.length; j++) {
  303.       if (this[i] == res[j]) {
  304.         repeat = true
  305.         break
  306.       }
  307.     }
  308.     if (!repeat) {
  309.       res.push(this[i])
  310.     }
  311.   }
  312.   return res
  313. }

  314. export {
  315.   GPS
  316. }
复制代码
回复 使用道具 举报
谢厅讲师达人认证 悬赏达人认证 活字格认证
金牌服务用户   /  发表于:2020-5-23 09:14:43
楼主
请贴全部代码或者上传工程文件
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部