Geolocation.getCurrentPosition:超时已过期

时间:2016-10-11 15:08:28

标签: geolocation ionic2

我正在使用Ionic2。

我使用以下代码,但收到错误:

import { Geolocation } from 'ionic-native';

    public getPosition(): void {
        if (this.markers && this.markers.length > 0) {
            var marker: google.maps.Marker = this.markers[0]; // only one
            this.latitude = marker.getPosition().lat();
            this.longitude = marker.getPosition().lng();
            this.getJobRangeSearch(this.searchQuery);
        } else {
            let options = {
                timeout: 10000,
                enableHighAccuracy: true
            };
            Geolocation.getCurrentPosition(options).then((position) => {
                this.latitude = position.coords.latitude;
                this.longitude = position.coords.longitude;
                this.getJobRangeSearch(this.searchQuery);
            }).catch((error) => {
                console.log(error);
                this.doAlert(error+' Timeout trying to get your devices Location');
            });
        }
    }

错误:

  

PositionError {message:"超时已过期",代码:3,PERMISSION_DENIED:   1,POSITION_UNAVAILABLE:2,TIMEOUT:3}

的package.json

"ionic-native": "^1.3.2",

谢谢

1 个答案:

答案 0 :(得分:0)

查看here表明我需要执行以下操作:

$ ionic plugin add cordova-plugin-geolocation