그래서 Google Maps 및 Ionic 2에서 작업하고 있습니다. Cordova에는 사용자의 위치 정보를 검색 할 수있는 플러그인이 있으며 플러그인에 대해 두 가지 질문이 있습니다. watch.unsubscribe()
및 Geolocation.clearWatch(watch)
: 내 질문에 언급하기 전에ionic 2 Geolocation clearWatch 또는 unsubscribe
는하지만, 여기에 사용자의 위치를보고 중지하는 방법은 두 가지가 있습니다, 내 코드
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입니다. 그러나
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'.
뭔가가 있습니까?
감사합니다! 그게 내 질문에 대한 답이야. BTW, 나는 당신이 마지막 줄에서'clearWatch (watchId)'를 의미했다고 생각한다. – Coffee
당신 말이 맞아요. Typo-tastic ☺️ 고정. – DaveAlden
ionic의 위치 정보 watchPosition에서 반환되는 관찰 가능 항목에 대한 구독 취소 방법이 없을 때 우리는 무엇을합니까? – Jahrenski