How to get the distance in a near func

In the




Syntax Example: near(predicate, [long, lat], distance)

How to get the actual distance from the result to the specified coordinates [long, lat]?
I want the results to be sorted by distance

Do you say a straight line? this is not possible in Dgraph. Your map lib/framework just needs the points and then it decides which route it gives you if it needs to generate a route with distance. And straight lines are not so useful. Even for helicopters :stuck_out_tongue:

There is also no sorting for the Geo type. Even if there was a way (it could be introduced) to tell the distance between two points, there would be no way to do sorting.

If we see more interest on this topic, we can make it a feature request in the future.

I get it
I thought that since the dgraph knows which points is NEAR to the point I gave,it must have calculated their distance in the backend already and I can get those value easily.

thanks for your explanation :smile:

1 Like

It does, but that calculations aren’t exposed, because they are not useful at first. And also it is necessary to create a support for geo in sorting. So that would be a feature request.

1 Like

I thought I saw somewhere already a request for geo sorting, idk.

I would find this useful and if it not available in the back-end, i will be doing it on the front-end. I don’t need exact distances but just a general idea as the bird flies. I want to give my users a rough idea how far apart two a set of locations are from the source.

If I am in city at lat,lng then is this location approximately 5 miles away or 500 miles away.