TypeError: Failed to execute 'watchPosition' on 'Geolocation': The callback provided as parameter 2 is not a function.
你說的對,這些參數都是錯誤的:
id = navigator.geolocation.watchPosition(success, error, options)
這麼一兩件事你可以嘗試是這樣做的:
let geoWatch = Geolocation.watchPosition(options, subscribeToPosition, showError);
// Success callback
private subscribeToPosition(positionObj): void {
this.data = positionObj;
console.log(positionObj);
}
// Error callback
private showError(errorObj): void {
// Handle the error.
console.log(errorObj);
}
======== ==============================
編輯:
我雖然我們採取了約navigator.Geolocation
API,但在那(真棒)後喬希是使用地理位置科爾多瓦插件通過Ionic Native
(對不起,我的壞)。
我可以看到in the documentation:
This API is based on the W3C Geolocation API Specification, and only executes on devices that don't already provide an implementation.
所以我認爲你應該檢查,如果你在一個Web應用程序(通過做this.platform.is('core')
)是,如果你是,那麼你需要添加以前sintax(帶回調)。但是,如果這是false
,那麼您知道您的應用正在移動設備上執行,並且您可以像使用代碼一樣使用ionic-native
sintax。我擔心你需要在真實的設備中測試它,只是爲了確保。
是真的,但我想保留我正在使用的打字稿語法。我遇到了一堆使用與我相同的代碼的例子,但是似乎沒有相同的錯誤 – vrijdrogenaam
但是通過傳遞迴調(在typescript sintax中定義)來調用方法也是打字稿。您可以添加這些代碼示例的鏈接,以便我們可以看看它們嗎?必須有我們缺少的東西... – sebaferreras
在這裏你去! http://www.joshmorony.com/adding-background-geolocation-to-an-ionic-2-application/ – vrijdrogenaam