Hi
I can get get the distance between my location and multiple locations from the Appery mongo Db but when I use XHR2 it does not work.
This is my call to the REST DB which returns all the records in the table perfectly
var url = "http://xxx.xxx.xxx.xxx/api/_table/rides";
var Rides = XHR2.send("GET", url, {
"headers": {
"X-DreamFactory-Api-Key": "83edb3c5b591ac2e15ed36d34224dexxxxxxf8e"
},
});
This is my response data:
{
"resource": [
{
"rideType": null,
"doThu": null,
"pickupRaduisFlex": null,
"maxPassengers": null,
"dateCreate": null,
"userID": 1,
"dropoffRadiusFlex": null,
"endLAT": null,
"pickupTime": "10:00",
"startLocation": "Johannesburg",
"arrivalTime": "11:00",
"endLNG": null,
"endLocation": "Pretoria",
"startLNG": "28.037612",
"startLAT": "-25.946367",
"onceOffDate": null,
"doFri": null,
"rideIsFull": null,
"rideID": 1,
"dateDeleted": null,
"doSat": null,
"doTues": null,
"deleted": null,
"doMon": null,
"doSun": null,
"dateUpdate": null,
"isOnceOff": null,
"doWed": null
},
{
"rideType": null,
"doThu": null,
"pickupRaduisFlex": null,
"maxPassengers": null,
"dateCreate": null,
"userID": 1,
"dropoffRadiusFlex": null,
"endLAT": null,
"pickupTime": "08:00",
"startLocation": "Durban",
"arrivalTime": "13:00",
"endLNG": null,
"endLocation": "Johannesburg",
"startLNG": "28.037800",
"startLAT": "-25.946900",
"onceOffDate": null,
"doFri": null,
"rideIsFull": null,
"rideID": 2,
"dateDeleted": null,
"doSat": null,
"doTues": null,
"deleted": null,
"doMon": null,
"doSun": null,
"dateUpdate": null,
"isOnceOff": null,
"doWed": null
}
]
}
Now I need to do a distance calculation and this is where the problem lies. I loop through the data but nothing is returned. This is my code.....
for (var i = 0; i < Rides.length; i++) {
Code: Select all
var lat = JSON.parse(Rides.body).Rides[i].startLAT;
var lng = JSON.parse(Rides.body).Rides[i].startLNG;
var distance = getDistance(lat, latitude, lng, longitude);
// If the customer's coordinates are within the radius,
// add the customer record to the results array
if (getDistance(lat, latitude, lng, longitude) ) it returns all the data above but without distance.
Please can you assist.
Thank you.