Hi
I used the tutorial https://devcenter.appery.io/tutorials...
to return details of customer from database.
I also need to return the actual distance that was calculated. Is this possible?
Thank you
Hi
I used the tutorial https://devcenter.appery.io/tutorials...
to return details of customer from database.
I also need to return the actual distance that was calculated. Is this possible?
Thank you
Hello Deon,
Please check this post:
https://getsatisfaction.com/apperyio/...
Thanks Evgene
That wont work. Results are mapped from the customers collection to a list. results.push(customers); is pushed from the database. How would I include the variable that gets the distance dynamically - getDistance(lat, latitude, lng, longitude)
I would need to combine this variable with the data from the collection and push it to the List.
I do not know how I can combine data from a collection and variable. Is this possible? Do you have an example, please?
I tried this but it pulls the distance through as a new seperate record.
var distance = getDistance(lat, latitude, lng, longitude);
results.push(customers, distance);
Thanks
Zzzz. I suppose this cant be done either
Deon, wouldn't you be able to add a distance field in the collection and then populate it with the server code after distance is calculated and then send that back? I did that and it worked great. But maybe I'm missing something.
Hi RobertJay
Thanks for your response. Yes I suppose I could however I want to minimize data access to keep the app as fast as I can. It already takes a long time just to locate two test devices. ![]()
Appreciate you assistance.
Hi Deon,
If you need just to add distance to current item you can change this part of code(from tutorial):
pre
Code: Select all
if (XHRResponse.status == 200) {
// Get coordinates from the response
var lat = JSON.parse(XHRResponse.body).results[0].geometry.location.lat;
var lng = JSON.parse(XHRResponse.body).results[0].geometry.location.lng;
// If the customer's coordinates are within the radius,
// add the customer record to the results array
if (getDistance(lat, latitude, lng, longitude) /pre With this part of code:
pre
Code: Select all
if (XHRResponse.status == 200) {
// Get coordinates from the response
var lat = JSON.parse(XHRResponse.body).results[0].geometry.location.lat;
var lng = JSON.parse(XHRResponse.body).results[0].geometry.location.lng;
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 (distance /pre Regards.
Hi Yuri
I know how to get the distance. My question is actually...
How do I return the distance and the merchant data from the collection together to diplay to the user?
Hello Deon,
Do you mean concatenate two service responses?
Please clarify.
Correct. I need to concatenate the data from the collection with the distance variable and return. This is what I have tried but it still only pushes the collection data and not the distance.
Code: Select all
for (var i = 0; i < customers.length; i++) {
// Get coordinates from the response
var lat = Number(customers[i].mylat);
var lng = Number(customers[i].mylng);
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) );