當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Geolocation.watchPosition方法代碼示例

本文整理匯總了TypeScript中@ionic-native/geolocation.Geolocation.watchPosition方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Geolocation.watchPosition方法的具體用法?TypeScript Geolocation.watchPosition怎麽用?TypeScript Geolocation.watchPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@ionic-native/geolocation.Geolocation的用法示例。


在下文中一共展示了Geolocation.watchPosition方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getLocation

  getLocation(){
    this.geolocation.getCurrentPosition().then(pos =>{
      this.latitude = pos.coords.latitude;
      this.longitude = pos.coords.longitude;
      console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude);
    });

    let watch = this.geolocation.watchPosition().subscribe(pos =>{
      console.log('lat: ' + pos.coords.latitude + ', lon: ' + pos.coords.longitude);
    });

    watch.unsubscribe();
  }
開發者ID:Jeffsummers2412,項目名稱:camera,代碼行數:13,代碼來源:geolocation.ts

示例2: ionViewDidLoad

 ionViewDidLoad() {
   console.log('ionViewDidLoad GpsLocationPage');
   this.geolocation.getCurrentPosition().then((resp) => {
     // resp.coords.latitude
     // resp.coords.longitude
     console.log("LAT :",resp.coords.latitude);
     console.log("LOG :",resp.coords.longitude);
    }).catch((error) => {
      console.log('Error getting location', error);
    });
    let watch = this.geolocation.watchPosition();
    watch.subscribe((data) => {
     // data can be a set of coordinates, or an error (if an error occurred).
     // data.coords.latitude
     // data.coords.longitude
     console.log("Data LAT :",data.coords.latitude);
     console.log("Data LOG :",data.coords.longitude);
    });
 }
開發者ID:NivKapade,項目名稱:ChuzDrApp,代碼行數:19,代碼來源:gps-location.ts

示例3: mapSetUp

    /*
        here is where the map object is initialized
        it is centered and zoomed in to an appropriate level and
        contained in the appropriate bounds
        and populated with all the markers
    */
    mapSetUp() {

      //here is where the phone's geolocation is first defined
      //there is also an error function just incase the setup was unsuccessful
      //var userLoc = undefined;
      this.geolocation.getCurrentPosition({timeout: 10000, enableHighAccuracy: true}).then((position) => {
    
          this.userLoc = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
          
      }).catch((error) =>{

                console.log('problem getting location', error);
                alert('code: ' + error.code +'\n'
                   + 'message: ' + error.message + '\n');
                this.userLoc = undefined;
      });

      //here is where the map is initialized, if the user's geolocation is defined and within mapBounds, 
      //then it is the map's center, otherwise the default center is used
      let options = {
         center: (this.userLoc !== undefined && this.mapBounds.contains(this.userLoc)) ? this.userLoc : this.areaCenter,
         zoom: 17,
         mapTypeId: google.maps.MapTypeId.ROADMAP
      }

      this.map = new google.maps.Map(document.getElementById("map"), options);

      //here is where we set up a "position watcher" that should listen to a change in the user's location and update the user's
      //marker accordingly
      this.locWatcher = this.geolocation.watchPosition()
                        .filter((p) => p.coords !== undefined)  
                        .subscribe(position => {
                            let newUserLoc = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
                            this.updateUserMark(newUserLoc);
                        });

    
    }
開發者ID:cs480-capstone,項目名稱:Tree-TreeFactory,代碼行數:44,代碼來源:integratedmap.ts

示例4: watchPosition

 watchPosition(options: GeolocationOptions = defaultOptions): Observable<Geoposition> {
   return this.geolocation.watchPosition(options);
 }
開發者ID:qwb0920,項目名稱:ext-ionic,代碼行數:3,代碼來源:geolocation.ts


注:本文中的@ionic-native/geolocation.Geolocation.watchPosition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。