Page 1 of 2

Distance calculation within REST

Posted: Fri Sep 05, 2014 4:38 pm
by sowmen choudhury

I have a query on calculating distance (google matrix api) within a database rest service. Both my services working fine separately but not sure how would I output distance for each list item.

So to elaborate I have list of addresses stored in a database and I want to get distance from users current location...


Distance calculation within REST

Posted: Fri Sep 05, 2014 4:58 pm
by Evgene Karachevtsev

Hello Sowmen,

You should call the service of the distance calculation for each address. Please look here how to combine 2 services: https://getsatisfaction.com/apperyio/...


Distance calculation within REST

Posted: Fri Sep 05, 2014 5:27 pm
by sowmen choudhury

Thanks for the quick reply Evgene...I am still not sure if I can replicate with my situation, I mean the JS part..

Let me explain a bit with some screen..

Here is the google rest

Image

Here is my database query - Image

Can you help me set the JS


Distance calculation within REST

Posted: Mon Sep 08, 2014 12:52 am
by Yurii Orishchuk

Hi Sowmen,

Here is a brief plan for this implementation:

1 Get current location and store it in some LSV(origin)

2 Add success event handler on list service and get all destinations.

4 Invoke "distance_metrics" service with parameters:
4.1 origin from LSV from 1st step.
4.2 destinations from 2nd step.

Here is code how to invoke service from JS:

pre

//You need to replace "serviceName" with your service datasource name.
//Also you need to set correct origins and destinations parameters.
serviceName.execute({data: {origins: "...", destinations: "..." } });

/pre

Note, you can send only 25 items at once. see details here: https://developers.google.com/maps/do...

Regards.


Distance calculation within REST

Posted: Tue Sep 09, 2014 5:11 am
by sowmen choudhury

Hi Yurii,

I could able to do that right but whre do I place this code as it tend to output same distance for all my list output fields.

sowmwn


Distance calculation within REST

Posted: Tue Sep 09, 2014 10:11 am
by Evgene Karachevtsev

Hello Sowmen,

Please look at this reply, there all the steps: https://getsatisfaction.com/apperyio/... Please let us know if something causes difficulties for you there. Either please provide us with a full description and screenshots of what you are doing.


Distance calculation within REST

Posted: Fri Sep 19, 2014 9:29 am
by sowmen choudhury

Hello Evgene,

I am still not able to send the data back to the label.

Please see my screens.

  1. My code in the marring JS.

    Image

    And My service response page... Image

    Now I just want to return the distance value..

    Please help me with the code...


Distance calculation within REST

Posted: Fri Sep 19, 2014 8:00 pm
by Evgene Karachevtsev

Hello Sowmen,

You have an error in your code
predata: {origins: "'+origin+'", destination: "'+destination+'"}/pre
and should be
predata: {origins: origin, destinations: destination}/pre
But your code is still not complete. Please look carefully at this answer: https://getsatisfaction.com/apperyio/... There all the steps, please let us know if anything is not clear


Distance calculation within REST

Posted: Sat Sep 20, 2014 3:13 am
by sowmen choudhury

Hey Thanks Evgene for the response.

I did followed the steps in the link now and got the service work as expected but just not able to output data...

My code..

Underline is where i think i have an issue.

Image

My console...

Image

Underline is what i want to output..

Thanks


Distance calculation within REST

Posted: Sun Sep 21, 2014 11:05 pm
by Yurii Orishchuk

HI Sowmen,

It seems you have attached same images.

We can not help cause of we can not see your service response.

But, on your screen shot from service "response" tab (https://d2r1vs3d9006ap.cloudfront.net...)

you should remove "[0]" from "data" object.

See details: http://prntscr.com/4p34fn/direct

If it does not help please provide us with your service response text. (for example save response to file and give it us)

Regards.