Geo Tools (Distance, Geohash…) API
Distance (haversine, Vincenty), bearing, destination, geohash, Google polyline, point in polygon, area, simplification and nearest points.
Pick an operation with op. distance (from, to) gives the great-circle distance (haversine) and the ellipsoidal distance on WGS 84 (Vincenty, millimetre accuracy) in metres, kilometres, miles and nautical miles, the initial and final bearing, compass direction and midpoint. destination gives the point reached from from after distance metres on a bearing. geohash encodes a point (precision 1-12) or decodes a geohash to its centre, bounding box, cell size and 8 neighbours. polyline encodes points to a Google encoded polyline or decodes a polyline (precision 5, or 6 for OSRM / Valhalla), with its length.
contains tells whether a point or a list of points lies inside a GeoJSON polygon (Polygon with holes, MultiPolygon, Feature or FeatureCollection, returning the matching features). measure gives the area (m², km², ha), perimeter, line length, bounding box and centroid of any GeoJSON. simplify reduces a line or polygon with Douglas-Peucker for a tolerance in metres. nearest sorts up to 10,000 points by distance from from (with limit and max_distance).
Points are "lat,lng", [lat, lng] or {"lat", "lng"} in WGS 84 degrees; GeoJSON keeps its own [lng, lat] order (RFC 7946). Pure calculation, nothing is stored; no routing or geocoding (see /v1/vn-geo for Vietnamese administrative units).
Parameters
| Name | In | Type | Required | Default | |
|---|---|---|---|---|---|
op | query|body | string | yes | distance, destination, geohash, polyline, contains, measure, simplify or nearest. | |
from | query|body | string | no | distance / destination / nearest: start point "lat,lng". | |
to | query|body | string | no | distance: end point "lat,lng". | |
bearing | query|body | number | no | destination: degrees clockwise from north. | |
distance | query|body | number | no | destination: distance in metres. | |
point | query|body | string | no | geohash (encode) / contains: a point "lat,lng". | |
geohash | query|body | string | no | geohash: hash to decode. | |
precision | query|body | number | no | geohash: length 1-12 (default 9); polyline: 5 (default) or 6. | |
polyline | query|body | string | no | polyline: encoded polyline to decode. | |
points | body|query | array | no | polyline (encode) / contains / simplify / nearest: [[lat, lng], …] or "lat,lng;lat,lng". | |
polygon | body | object | no | contains: GeoJSON Polygon / MultiPolygon / Feature / FeatureCollection. | |
geojson | body | object | no | measure / simplify: any GeoJSON geometry, Feature or FeatureCollection. | |
tolerance | query|body | number | no | 10 | simplify: tolerance in metres. |
limit | query|body | number | no | 10 | nearest: points returned. |
max_distance | query|body | number | no | nearest: only points within this many metres. |
Example
curl "https://apibox.io.vn/v1/geo-tools?op=distance&from=21.0285,105.8542&to=10.7769,106.7009" \
-H "Authorization: Bearer YOUR_API_KEY"const res = await fetch('https://apibox.io.vn/v1/geo-tools?op=distance&from=21.0285,105.8542&to=10.7769,106.7009', {
method: 'GET',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
},
});
const data = await res.json();
console.log(data);import requests
res = requests.get(
"https://apibox.io.vn/v1/geo-tools?op=distance&from=21.0285,105.8542&to=10.7769,106.7009",
headers={"Authorization": "Bearer YOUR_API_KEY"},
timeout=30,
)
print(res.json())<?php
$ch = curl_init('https://apibox.io.vn/v1/geo-tools?op=distance&from=21.0285,105.8542&to=10.7769,106.7009');
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ['Authorization: Bearer YOUR_API_KEY'],
]);
$response = curl_exec($ch);
print_r(json_decode($response, true));Response
{
"op": "distance",
"from": [
21.0285,
105.8542
],
"to": [
10.7769,
106.7009
],
"haversine": {
"meters": 1143505.99,
"kilometers": 1143.50599,
"miles": 710.54168,
"nautical_miles": 617.443839
},
"vincenty": {
"meters": 1138049.892,
"kilometers": 1138.049892,
"miles": 707.151418,
"nautical_miles": 614.497782
},
"initial_bearing": 175.3078,
"final_bearing": 175.5408,
"compass": "S",
"midpoint": [
15.903112,
106.28837
],
"method": "haversine on a sphere of radius 6371008.8 m; Vincenty inverse formula on the WGS 84 ellipsoid (bearings from Vincenty)",
"note": "Points are [lat, lng] in WGS 84 degrees; GeoJSON positions are [lng, lat] as in RFC 7946."
}
Use cases
- Compute delivery distances and sort shops or drivers by proximity
- Check GPS attendance check-ins against a geofence polygon
- Decode route polylines from Google, OSRM or Valhalla
- Store and query locations by geohash prefix
FAQ
Haversine or Vincenty?
Haversine uses a sphere and can be off by up to about 0.5%; Vincenty uses the WGS 84 ellipsoid and is accurate to the millimetre. Both are returned.
Which coordinate order do you use?
Points are lat, lng (as on phones and maps); GeoJSON input and output use lng, lat as required by the standard.
How is area computed?
With the spherical excess formula used by turf.js (radius 6378137 m), holes subtracted; accurate enough for parcels, wards and delivery zones.
Related APIs
JSON Validator
Check JSON syntax with exact line and column of errors, and validate data against a JSON Schema (draft 4, 7, 2019-09 or 2020-12).
{ }JSON Formatter
Pretty print JSON with 0-8 spaces or tabs, minify it, or sort object keys recursively. Syntax errors are reported with line and column.
CSVCSV to JSON
Convert CSV into an array of JSON objects using the header row, with delimiter auto-detection, number and boolean typing, and row-level errors.