sowmen choudhury
Posts: 0
Joined: Sat Feb 01, 2014 3:32 pm

Distance calculation within REST

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...

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

Distance calculation within REST

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/...

sowmen choudhury
Posts: 0
Joined: Sat Feb 01, 2014 3:32 pm

Distance calculation within REST

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

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

Distance calculation within REST

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.

sowmen choudhury
Posts: 0
Joined: Sat Feb 01, 2014 3:32 pm

Distance calculation within REST

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

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

Distance calculation within REST

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.

sowmen choudhury
Posts: 0
Joined: Sat Feb 01, 2014 3:32 pm

Distance calculation within REST

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...

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

Distance calculation within REST

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

sowmen choudhury
Posts: 0
Joined: Sat Feb 01, 2014 3:32 pm

Distance calculation within REST

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

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

Distance calculation within REST

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.

Return to “Issues”