离子前端和laravel后端距离计算

离子前端和laravel后端距离计算,laravel,ionic4,Laravel,Ionic4,我将应用程序数据保存在mysql中。我使用Laravel Restfull获取lat、lng和其他值 这是离子。。。page.ts我的代码 import { NativeGeocoder, NativeGeocoderResult, NativeGeocoderOptions, } from "@ionic-native/native-geocoder/ngx"; import { Geolocation } from "@ionic-native/g

我将应用程序数据保存在mysql中。我使用Laravel Restfull获取lat、lng和其他值

这是离子。。。page.ts我的代码

 import {
 NativeGeocoder,
 NativeGeocoderResult,
 NativeGeocoderOptions,
 } from "@ionic-native/native-geocoder/ngx";
 import { Geolocation } from "@ionic-native/geolocation/ngx";

constructor(
private navCtrl: NavController,
private nativeGeocoder: NativeGeocoder,
private api: ApiService,
private util: UtilService,
private geolocation: Geolocation
) {
let options: NativeGeocoderOptions = {
  useLocale: true,
  maxResults: 5,
};
this.util.startLoad();
this.geolocation
  .getCurrentPosition()
  .then((resp) => {
    this.api
      .getDataWithToken("category/" + this.api.id + "/business")
      .subscribe(
        (res: any) => {
          if (res.success) {
            this.data = res.data;
            this.data.forEach(async (element) => {
              this.lat = resp.coords.latitude;
              this.lng = resp.coords.longitude;
              await this.nativeGeocoder
                .forwardGeocode(element.address, options)
                .then(async (result: NativeGeocoderResult[]) => {
                  element.lat = await result[0].latitude;
                  element.lng = await result[0].longitude;
                  element.distance = await Number(
                    this.distance(
                      resp.coords.latitude,
                      resp.coords.longitude,
                      element.lat,
                      element.lng,
                      "K"
                    ).toFixed(2)
                  );

                  this.util.dismissLoader();
                })
                .catch((error: any) => console.log("error", error));
            });
          }
        },
        (err) => {
          this.util.dismissLoader();
          this.err = err.error.errors;
        }
      );
  })
  .catch((error) => {
    this.util.dismissLoader();
    console.log("Error getting location", error);
  });
}

代码从LaravelAPI中获取mysql数据,如屏幕截图所示。我想要的是获取用户的位置,计算到json中lat和lng值的距离(km),并将其打印为json的值