2016-10-11 63 views
0

我正在使用Ionic2。Geolocation.getCurrentPosition:超時已過期

我使用下面的代碼,但得到一個錯誤:

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: "Timeout expired", code: 3, PERMISSION_DENIED: 1, POSITION_UNAVAILABLE: 2, TIMEOUT: 3}

的package.json

"ionic-native": "^1.3.2", 

謝謝

回答

0

尋找here節目,我需要做到以下幾點:

$ ionic plugin add cordova-plugin-geolocation 
相關問題