首页 > 解决方案 > 如何从角度中的地址获取经度和纬度 - 离子4

问题描述

我在 ionic 4 上构建了以下代码。它适用于 Andriod 设备,但不适用于 IOS。

我发现要让 IOS 工作,我需要计算出经度和纬度并将其传递进去。

我尝试了一个测试并硬编码了经度和纬度,它可以在 IOS 设备上运行。

但是,我需要一种从某个位置获取经度和纬度的方法。

我已经看到了地理位置,但这并没有通过一个位置。

this.geolocation.getCurrentPosition()
this.geolocation.watchPosition()

这是我的代码,如何从该位置获取经度和纬度?

location = '10 Downing St, Westminster, London'

GoToUrl(location) {
   if (this.platform.is('android')) {
     window.location.href = 'geo:' + '?q=' + location;
   } 
   else {
     const destination = '51.503391' + ',' + '-0.127630';
     window.open('maps://?q=' + destination + '_system');
     }
   }
 }

标签: angulartypescriptgeolocationionic4

解决方案


推荐阅读