Need to convert decimal coordinates to the traditional degrees, minutes, seconds (DMS) format? This guide covers everything about decimal to DMS conversion via API, including formatting options, precision control, and implementation examples.
Why Convert to DMS?
While decimal degrees are convenient for computation, DMS format is often preferred for human-readable display. It's commonly used in:
- Navigation and aviation
- Printed maps and atlases
- Surveying and legal documents
- GPS device displays
The Conversion Formula
To convert decimal degrees to DMS:
Degrees = integer part of decimal
Minutes = integer part of ((decimal - degrees) × 60)
Seconds = ((decimal - degrees) × 60 - minutes) × 60
40 degrees, 0.7128 × 60 = 42.768 minutes, 0.768 × 60 = 46.08 seconds
Using the Decimal to DMS API
TinyFn provides a simple endpoint to convert decimal coordinates:
POST https://api.tinyfn.io/v1/geo/decimal-to-dms
Headers: X-API-Key: your-api-key
Content-Type: application/json
{
"lat": 40.7128,
"lng": -74.0060
}
{
"latitude": {
"degrees": 40,
"minutes": 42,
"seconds": 46.08,
"direction": "N",
"formatted": "40° 42' 46.08\" N"
},
"longitude": {
"degrees": 74,
"minutes": 0,
"seconds": 21.6,
"direction": "W",
"formatted": "74° 0' 21.6\" W"
},
"formatted": "40° 42' 46.08\" N, 74° 0' 21.6\" W"
}
Parameters
| Parameter | Type | Description |
|---|---|---|
lat |
number | Decimal latitude (-90 to 90) |
lng |
number | Decimal longitude (-180 to 180) |
seconds_precision |
integer | Decimal places for seconds (default: 2) |
format |
string | Output format: "standard", "compact", "unicode" (default: "standard") |
Code Examples
JavaScript / Node.js
const response = await fetch(
'https://api.tinyfn.io/v1/geo/decimal-to-dms',
{
method: 'POST',
headers: {
'X-API-Key': 'your-api-key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
lat: 40.7128,
lng: -74.0060
})
}
);
const data = await response.json();
console.log(data.formatted); // "40° 42' 46.08\" N, 74° 0' 21.6\" W"
Python
import requests
response = requests.post(
'https://api.tinyfn.io/v1/geo/decimal-to-dms',
headers={'X-API-Key': 'your-api-key'},
json={
'lat': 40.7128,
'lng': -74.0060
}
)
data = response.json()
print(data['formatted']) # "40° 42' 46.08\" N, 74° 0' 21.6\" W"
cURL
curl -X POST "https://api.tinyfn.io/v1/geo/decimal-to-dms" \
-H "X-API-Key: your-api-key" \
-H "Content-Type: application/json" \
-d '{"lat": 40.7128, "lng": -74.0060}'
Common Use Cases
- Map Display: Show coordinates in human-readable DMS format
- Report Generation: Format coordinates for printed reports
- Data Export: Export coordinates in DMS for external systems
- User Interfaces: Display location information in traditional format
- Navigation Apps: Show coordinates in pilot/sailor-friendly format
Best Practices
- Choose appropriate precision: 2 decimal places for seconds is usually sufficient
- Use Unicode format: For modern displays, the Unicode format looks cleaner
- Always show direction: Use N/S/E/W indicators instead of +/- signs for clarity
- Round consistently: Ensure consistent rounding across your application
Use via MCP
Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:
{
"mcpServers": {
"tinyfn-geo": {
"url": "https://api.tinyfn.io/mcp/geo/",
"headers": {
"X-API-Key": "your-api-key"
}
}
}
}
See all geolocation tools available via MCP in our Geolocation MCP Tools for AI Agents guide.
Try the Decimal to DMS API
Get your free API key and start converting coordinates in seconds.
Get Free API Key