订阅可从服务观察到的.map

时间:2018-07-12 14:48:44

标签: angular typescript rxjs

我从服务中获得了此功能,我需要获取.lat值并在我的地理位置组件的Haversine()方法中进行订阅。

服务

Full code:
//select current user selected row
var settingsRange = settingsSheet.getRange("B2");
var settingsValues = settingsRange.getValues();
var results = settingsValues[0][0];//i.e. 3;4||8:100
var result1 = results.split("||");
var result2 = result1[0].split(";");//i.e. 3,4
var result3 = result1[1].split(":");//i.e. 8,100
var i;

//hide individual rows
for (i = 0; i < result2.length; i++) { 
  //Browser.msgBox(result2[i]);    
  if (result2[i]){
    mySheet.hideRows(result2[i]);  
  }
}
  //hide row range
  mySheet.hideRows(result3[0],result3[1]);

  //select current user selected row
  var settingsRange = settingsSheet.getRange("B1");
  var settingsValues = settingsRange.getValues();
  var cell = mySheet.getRange("B" + settingsValues[0][0]);
  mySheet.setCurrentCell(cell);  

}

地理位置类

getHoleLat(id: number | string) {
return this.getHoles().pipe(
  map(holes => holes.find(hole => hole.id === +id).lat)
  );

}

我要订阅的数据

 Haversine(): void {

    if (navigator.geolocation) {
        navigator.geolocation.getCurrentPosition( x => {

      this.myLat = x.coords.latitude;
      this.myLng = x.coords.longitude;

      // this.courseLat = this._mont.getHoleLat();
      // this.courseLng = this._mont.getHoleLng();


    console.log(`longitude: ${ this.courseLat } | latitude: ${ this.courseLng }`);
    console.log(`longitude: ${ this.myLat } | latitude: ${ this.myLng }`);


    const myCoords: GeoCoord = {
      latitude: this.myLat,
      longitude: this.myLng
    };

    const courseData: GeoCoord = {
      latitude: this.courseLat,
      longitude: this.courseLng
    };

    this.metres = this._haversine.getDistanceInMeters(myCoords, courseData);
    this.yards = this._haversine.getDistanceInYards(myCoords, courseData);
    this.kilometres = this._haversine.getDistanceInKilometers(myCoords, courseData);
    this.miles = this._haversine.getDistanceInMiles(myCoords, courseData);

    this.metres = this.metres.toFixed(2);
    this.yards = this.yards.toFixed(2);
    this.kilometres = this.kilometres.toFixed(2);
    this.miles = this.miles.toFixed(2);
 });
}

0 个答案:

没有答案