Examples
Practical code examples and snippets to help you integrate geog location services into your applications quickly and efficiently.
Basic API Usage
Simple examples to get you started
Place Search
Search for places, businesses, and points of interest
Search for coffee shops
curl -H "Authorization: Bearer YOUR_API_KEY" \
"https://api.geog.dev/v1/places/search?q=coffee&lat=37.7749&lng=-122.4194&limit=5"Using fetch API
const response = await fetch(
'https://api.geog.dev/v1/places/search?q=coffee&lat=37.7749&lng=-122.4194&limit=5',
{
headers: {
'Authorization': 'Bearer YOUR_API_KEY'
}
}
);
const data = await response.json();
console.log(data.features);Using requests library
import requests
url = "https://api.geog.dev/v1/places/search"
headers = {"Authorization": "Bearer YOUR_API_KEY"}
params = {
"q": "coffee",
"lat": 37.7749,
"lng": -122.4194,
"limit": 5
}
response = requests.get(url, headers=headers, params=params)
data = response.json()
for place in data['features']:
print(place['properties']['name'])Using cURL
<?php
$url = "https://api.geog.dev/v1/places/search?q=coffee&lat=37.7749&lng=-122.4194&limit=5";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Authorization: Bearer YOUR_API_KEY'
]);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
foreach ($data['features'] as $place) {
echo $place['properties']['name'] . "\n";
}
?>Geocoding
Convert addresses to coordinates and vice versa
Forward Geocoding
GET /v1/places/geocode/forward?q=1600+Amphitheatre+ParkwayReverse Geocoding
GET /v1/places/geocode/reverse?lat=37.4220&lng=-122.0844Framework Integration
Examples for popular frameworks and libraries
React + Mapbox
Interactive map with place search
Coming SoonBuild a React component that integrates geog place search with Mapbox GL JS.
Vue + Leaflet
Vector tiles with Leaflet
Coming SoonDisplay geog vector tiles in a Vue.js application using Leaflet.
Node.js API
Server-side geocoding service
Coming SoonCreate a Node.js API that uses geog for address validation and geocoding.
Interactive Examples
Try out the APIs in your browser
Interactive Playground Coming Soon
We're building an interactive playground where you can test API endpoints directly in your browser.