Getting distance between two points

This forum contains topics that were moved from Get Satisfaction
Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Getting distance between two points

Post by Deon »

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

Evgene Karachevtsev
Posts: 12
Joined: Mon Apr 28, 2014 1:12 pm

Getting distance between two points

Post by Evgene Karachevtsev »

Hello Deon,

Please check this post:
https://getsatisfaction.com/apperyio/...

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Getting distance between two points

Post by Deon »

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

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Getting distance between two points

Post by Deon »

Zzzz. I suppose this cant be done either

RobertJay
Posts: 0
Joined: Fri Jun 15, 2012 1:32 pm

Getting distance between two points

Post by RobertJay »

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.

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Getting distance between two points

Post by Deon »

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.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Getting distance between two points

Post by Yurii Orishchuk »

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.

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Getting distance between two points

Post by Deon »

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?

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Getting distance between two points

Post by Alena Prykhodko »

Hello Deon,

Do you mean concatenate two service responses?
Please clarify.

Deon
Posts: 0
Joined: Sun Jun 30, 2013 6:00 am

Getting distance between two points

Post by Deon »

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) );
Post Reply