I have some existing data in my neo4j database. I want to calculate distance from one node to another nodes based on longitude and latitude which are present with node. For that I want to create spatial Index on my existing data but I don't know how to create that index.
Are you using the spatial extension to create an OSMLayer? If not, and you just want the geodesic between to points, you can use the haversine
function.
http://neo4j.com/docs/stable/query-functions-mathematical.html#functions-haversin
CREATE (ber:City { lat: 52.5, lon: 13.4 }),(sm:City { lat: 37.5, lon: -122.3 })
RETURN 2 * 6371 * asin(sqrt(haversin(radians(sm.lat - ber.lat))+ cos(radians(sm.lat))*
cos(radians(ber.lat))* haversin(radians(sm.lon - ber.lon)))) AS dist