我正在开发一种工具,可以将 Google 位置历史记录提供的 JSON 转换为不同的格式,因此我可以将它与 Leaflet 热图插件一起使用。现在的问题是转换整数。我想要实现的是:
Positive Longitudes
1717485672 -> 171.7485672
115855930 -> 11.5855930
99811421 -> 9.9811421
Negative Longitudes
-99811421 -> -9.9811421
到目前为止我尝试了什么:
var longitude = "99811421";
longitude.replace(/(^([2-9]|1[0-9]))/, '$1.');
但是,这只适用于从 20000000 到 190000000 的范围。这对德国来说足够了,但对全世界来说还不够 ;)
知道怎么做吗?
最佳答案
此函数将为您“转换”数字,但实际上它所做的只是将数字除以 107
function num(x){ return x/10000000 }
关于javascript - 将 Google Location LatLong 整数转换为 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25587005/