【发布时间】:2017-08-15 14:38:34
【问题描述】:
所以我正在使用 Google Maps 和 Ionic 2。Cordova 有一个用于检索用户地理位置的插件,我有两个关于该插件的问题。
但在我提出问题之前,这是我的代码
import { Geolocation } from 'ionic-native';
watchPosition(marker) {
let watch = Geolocation.watchPosition({
//enableHighAccuracy: true
});
watch.subscribe((pos) => {
marker.setPosition({
lat: pos.coords.latitude,
lng: pos.coords.longitude
});
});
// stop watching if the user starts dragging the map
this.map.addListener('dragstart', () => {
// There might be two ways to do this, but non of them works
watch.unsubscribe();
Geolocation.clearWatch(watch);
});
}
AFAIK,有两种方法可以停止查看用户的位置:
watch.unsubscribe()和Geolocation.clearWatch(watch)。但是,我不知道除了unsubscribe的类型是Observable而另一个是从Geolocation插件导入的有什么区别。我应该使用哪一个?上面的问题实际上是微不足道的,我现在最重要的问题是它们都不起作用。
watch.unsubscribe()给出[ts] Property 'unsubscribe' does not exist on type 'Observable<Geoposition>'.和Geolocation.clearWatch(watch)给我的错误[ts] Property 'clearWatch' does not exist on type 'typeof Geolocation'.我有什么遗漏吗?
【问题讨论】:
标签: cordova ionic-framework geolocation ionic2 cordova-plugins