javascript - 如何使用 Nativescript 获取两个位置之间的距离
问题描述
当我有两个位置时,我想获得距离。
首先:我从geoLocation
.
geoLocation.isEnabled().then(enabled => {
console.log('enabled', enabled)
if (!enabled) {
geoLocation.enableLocationRequest().then(() => geoLocation.watchLocation(location => {
this.currentGeoLocation = location;
}, error => {
alert(error);
console.log('error', error)
}, {
desiredAccuracy: 3,
updateDistance: 10,
minimumUpdateTime: 1000 * 1
}));
} else {
geoLocation.watchLocation(location => {
this.currentGeoLocation = location;
}, error => {
alert(error);
console.log('error', error)
}, {
desiredAccuracy: 3,
updateDistance: 10,
minimumUpdateTime: 1000 * 1
});
}
}
this.currentGeoLocation.longitude
并this.currentGeoLocation.latitude
获取坐标。
第二:
从这个功能:
getallprod() {
this.ws.getallprod().subscribe(
items => {
this.items = items;
console.log(this.items)
},
err => console.error('err', err),
() => console.log('error')
);
}
我得到这个带有其他坐标的 JSON:
JS: [{
JS: "pro_id": "6969",
JS: "name": "Pharmacy",
JS: "longitude": 41.3257,
JS: "latitude": 19.8029
JS: }, {
JS: "pro_id": "525",
JS: "name": "Test ",
JS: "longitude": 41.3253,
JS: "latitude": 19.8013
JS: }]
我在这里看到如何计算距离
function getDistance(loc1, loc2) {
loc1 = this.currentGeoLocation.longitude +this.currentGeoLocation.latitude;
loc2 = this.items.longitude+this.items.latitude;
console.log("Distance between loc1 and loc2 is: " + distance(loc1, loc2));
}
错误:无法在数字“61.126601199999996”上创建属性“android”
解决方案
推荐阅读
- android - libgdx Gdx.graphics.getWidth 没有返回正确的值
- git - 如何为 git commit 创建 ZSH 别名/函数,提示用户输入用作提交消息?
- python - Readlines 只读取我的文本文件中的第一行
- javascript - 按属性动态调用对象中的方法
- postgresql - 如何获得在 postgres 中创建角色的权限
- c - 如何从c中的另一个函数引用数组?
- python - 使用 praw 抓取 Reddit 的有效方法?
- excel - 有没有办法在一个单元格中执行 5 种不同的数字格式或编写 VBA 脚本以根据值生成数字格式?
- python-3.x - Selenium 找不到 CSS 选择器
- function - 为什么我在 Mathematica 函数中得到 Null?