[Solved] How to find distance between 2 points in miles

Are you looking for help?

I understand how to query for locations near me.

I am wondering if it possible to return the distance from my reference point to each resulting point in the response when using a GET request.

currently, I’m making this GET call

/data/thunkableLocations?props=distanceOnSphere('POINT(-85.66061443893842 42.375649975692355)', location) as distanceToPoint

this too

distanceOnSphere(location, 'POINT(-85.66061443893842 42.375649975692355)') as distanceToPoint

and the response returns the correct points as shown in this map from the console

but the response I get has weird distances

[{"___class":"thunkableLocations","distanceToPoint":10363.067457467047,"objectId":"1B28DBCE-1921-4A4E-AE5F-D6A48EE13482"},
{"___class":"thunkableLocations","distanceToPoint":7387126.106273545,"objectId":"2E78DEBA-27AE-4889-BB3F-865FD1864351"},
{"___class":"thunkableLocations","distanceToPoint":17021.551426929374,"objectId":"32800FF9-0AC9-4908-83B6-639DE2EA6F93"},
{"___class":"thunkableLocations","distanceToPoint":13717.133596368107,"objectId":"66CE00DB-4FC3-4467-9E5C-77B4A9B03571"},
{"___class":"thunkableLocations","distanceToPoint":18516.96809727143,"objectId":"684E1B1D-DA88-42C9-A720-552F4333EAF2"},
{"___class":"thunkableLocations","distanceToPoint":11288.106529244586,"objectId":"6B9E4AFF-A759-4FB9-AF17-7CDA01CF7836"},
{"___class":"thunkableLocations","distanceToPoint":13032.007653789047,"objectId":"77C80B91-631E-4E90-8331-60E070196C01"},
{"___class":"thunkableLocations","distanceToPoint":7387125.883872176,"objectId":"A50CA1FA-35E8-4F42-A42E-9A0DED991858"},
{"___class":"thunkableLocations","distanceToPoint":33103.63790543043,"objectId":"AD1955B9-2507-42EE-978B-1B1A666A779F"},
{"___class":"thunkableLocations","distanceToPoint":15702.96936094333,"objectId":"BA83C418-DEB8-4301-985C-75221FE8386C"}]

[UPDATE] upon further reading, i see that distances are returned in meters. this is correct info!

Is there anyway to convert these to miles in the response body?

got it!

distanceOnSphere('POINT(-85.66061443893842 42.375649975692355)', location) * 0.000621371 as milesToPoint

thanks to @oleg.vyalh on Slack

1 Like

Hi, @jared_gibb

Sorry for a long wait. Is the variant offered by @oleg-vyalyh on Slack solved you issue?

Regards,
Marina

Yes! So sorry!!