Showing results for 
Search instead for 
Did you mean: 

Head's Up! Site migration is underway. Phase 2: migrate recent content

Distance calculation

Node Link

I need your advice.

I have different bus stop (nodes) with their GPS geographic position (longitude, latitude).
is there any way in neo4j to calculate the distance on the fly by road (or directly if it's not possible) according to the chosen stops?

Thank you for your suggestion.

By the way, i'm new in Neo4j and trying to learn.


Graph Buddy

Hi balbreaker75

I am not sure about the details of your usecase but neo4j has a distance function that can calculate distance between two points with longtitude and latitude. Here is an example:

MATCH (s1:BusStop)-[:TRAVEL_ROUTE]->(s2:BusStop)
WITH point({ longitude: s1.longitude, latitude: s1.latitude }) AS source, point({ longitude: s2.longitude, latitude: s2.latitude }) AS destination
RETURN round(distance(source, destination)) AS travelDistance

You can find more info here:

Thanks for your response.

in my sources (json file) i have:
"nodes": [
"stop_id" : "A",
"longitude" : 2.3756,
"latitude" : 48.8415
"stop_id" : "B",
"longitude" : 2.3271,
"latitude" : 48.8911

and i would like create de relation (A)<-[:TRAVEL_ROUTE]->(B) if the "stop_id" values are different.

So check, something like

IF a.longitude <> b.longitude AND a.lattitude <> b.lattitude
CREATE (a)-[travel_route]-(b) ?

If you want to calculate the distance by road you could probably use google or openmaps API