1

I want to get distance when I have two location.

In first: I get current location from geoLocation.

geoLocation.isEnabled().then(enabled => {
    console.log('enabled', enabled)
    if (!enabled) {
        geoLocation.enableLocationRequest().then(() => geoLocation.watchLocation(location => {
            this.currentGeoLocation = location;
        }, error => {
            alert(error);
            console.log('error', error)
        }, {
                desiredAccuracy: 3,
                updateDistance: 10,
                minimumUpdateTime: 1000 * 1
            }));
    } else {
        geoLocation.watchLocation(location => {
            this.currentGeoLocation = location;

        }, error => {
            alert(error);
            console.log('error', error)
        }, {
                desiredAccuracy: 3,
                updateDistance: 10,
                minimumUpdateTime: 1000 * 1
            });
    }
}

this.currentGeoLocation.longitude and this.currentGeoLocation.latitude get coordinates.

Second:

From this finction :

   getallprod() {
        this.ws.getallprod().subscribe(
            items => {
                this.items = items;
                console.log(this.items)
            },
            err => console.error('err', err),
            () => console.log('error')
        );
    }

I get this JSON with other coordinates:

JS: [{
JS:   "pro_id": "6969",
JS:   "name": "Pharmacy",
JS:   "longitude": 41.3257,
JS:   "latitude": 19.8029
JS: }, {
JS:   "pro_id": "525",
JS:   "name": "Test ",
JS:   "longitude": 41.3253,
JS:   "latitude": 19.8013
JS: }]

I see in here how to calculate distance

function getDistance(loc1, loc2) {
loc1 = this.currentGeoLocation.longitude +this.currentGeoLocation.latitude;
loc2 = this.items.longitude+this.items.latitude;
    console.log("Distance between loc1 and loc2 is: " + distance(loc1, loc2));
}

error: Cannot create property 'android' on number '61.126601199999996'

Alon Bi
  • 83
  • 6

0 Answers0