---
updatedAt: 2026-01-08T05:18:15.000Z
agentTools:
  projectIndex: https://docs.getfastah.com/llms.txt
---

# Geodata with Neo4j

A primer on saving and operating on geolocation coordinates (latitude and longitude) in Neo4j

[Neo4j](https://neo4j.com/docs/getting-started/) stores geographical data using the built-in [Point datatype](https://neo4j.com/docs/python-manual/current/data-types/#_spatial_types). This type models the Earth as an ellipsoid, so distance calculations use accurate geodetic math instead of flat 2D approximations.

## Create nodes with point geometry

Use Neo4j's [point() function](https://neo4j.com/docs/cypher-manual/current/functions/spatial/#functions-point) to store geolocation data from the [Fastah API](/reference/get-ip-geolocation) as a spatial property. The API returns `locationData.lat` and `locationData.lng`:

```cypher
UNWIND [
  { ip: "8.8.8.8",   lng: 144.94, lat: -37.84 },
  { ip: "14.1.82.2", lng: 151.20, lat: -33.86 }
] AS event

CREATE (:IPAddress {
  ip: event.ip,
  location: point({
    latitude: event.lat,
    longitude: event.lng
  })
});
```

## Calculate distance between IPs

Use [point.distance()](https://neo4j.com/docs/cypher-manual/current/functions/spatial/#functions-distance) to find the distance between two points. We round to two decimal places since IP-based geolocations are approximate:

```cypher
MATCH (a:IPAddress { ip: "8.8.8.8" }),
      (b:IPAddress { ip: "14.1.82.2" })

RETURN
  a.ip AS fromIp,
  b.ip AS toIp,
  round(
    point.distance(a.location, b.location) / 1000,
    2
  ) AS distanceKm;
```