Copy page

Copy page as Markdown for LLMs

View as Markdown

View this page as plain text


Open in ChatGPT

Ask ChatGPT about this page

Open in Claude

Ask Claude about this page

Location API

Introducing the Location API, a simple and reliable way to fetch geographical location details using a place name, city name, or location search query. This API is designed for websites, mobile apps, chatbots, CRM dashboards, astrology platforms, or any application that requires location-based information.

The API allows you to search for a location by passing a place name through the request body and returns the corresponding location information.


API Endpoint

POST https://geolocation.divineapi.com/location

Guide: Use this endpoint to retrieve geographical information for a given place.


Headers

NameTypeDescription
Authorization*StringYour API Access Token. Example: Bearer {token}

Fields marked with * are mandatory.


Request Body

NameTypeDescription
api_key*StringYour API key from the DivineAPI dashboard.
place*StringText to search for a location. Must contain at least 3 characters. Leading and trailing spaces are ignored. Example: Patna, New Delhi, New York.

200: OK 

{
    "status": "success",
    "code": 200,
    "message": "Request successful",
    "data": {
        "count": 10,
        "query": "patna",
        "results": [
            {
                "place_id": 1260091,
                "name": "Patna",
                "full_name": "Patna, Bihar, India",
                "country": "IN",
                "admin1": "Bihar",
                "latitude": 25.41667,
                "longitude": 85.16667,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 5838465
            },
            {
                "place_id": 12685607,
                "name": "Patna Rural",
                "full_name": "Patna Rural, Bihar, India",
                "country": "IN",
                "admin1": "Bihar",
                "latitude": 25.58486,
                "longitude": 85.16871,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 1771140
            },
            {
                "place_id": 1260086,
                "name": "Patna",
                "full_name": "Patna, Bihar, India",
                "country": "IN",
                "admin1": "Bihar",
                "latitude": 25.59408,
                "longitude": 85.13563,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 1684297
            },
            {
                "place_id": 12683334,
                "name": "Patnagarh",
                "full_name": "Patnagarh, Odisha, India",
                "country": "IN",
                "admin1": "Odisha",
                "latitude": 20.76025,
                "longitude": 83.11076,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 168325
            },
            {
                "place_id": 1260082,
                "name": "Patnāgarh",
                "full_name": "Patnāgarh, Odisha, India",
                "country": "IN",
                "admin1": "Odisha",
                "latitude": 20.70833,
                "longitude": 83.13263,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 21024
            },
            {
                "place_id": 1694370,
                "name": "Patnanungan",
                "full_name": "Patnanungan, Calabarzon, Philippines",
                "country": "PH",
                "admin1": "Calabarzon",
                "latitude": 14.81667,
                "longitude": 122.15,
                "timezone": "Asia/Manila",
                "timezone_value": 8,
                "population": 15554
            },
            {
                "place_id": 1694369,
                "name": "Patnanungan",
                "full_name": "Patnanungan, Calabarzon, Philippines",
                "country": "PH",
                "admin1": "Calabarzon",
                "latitude": 14.78333,
                "longitude": 122.18333,
                "timezone": "Asia/Manila",
                "timezone_value": 8,
                "population": 6901
            },
            {
                "place_id": 2640574,
                "name": "Patna",
                "full_name": "Patna, Scotland, United Kingdom",
                "country": "GB",
                "admin1": "Scotland",
                "latitude": 55.36406,
                "longitude": -4.50594,
                "timezone": "Europe/London",
                "timezone_value": 0,
                "population": 2190
            },
            {
                "place_id": 10532578,
                "name": "Patna",
                "full_name": "Patna, Madhya Pradesh, India",
                "country": "IN",
                "admin1": "Madhya Pradesh",
                "latitude": 24.52205,
                "longitude": 81.52903,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 0
            },
            {
                "place_id": 10457447,
                "name": "Patna",
                "full_name": "Patna, Madhya Pradesh, India",
                "country": "IN",
                "admin1": "Madhya Pradesh",
                "latitude": 23.56601,
                "longitude": 79.85514,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 0
            }
        ]
    },
    "attribution": "Place data © GeoNames (geonames.org), CC BY 4.0"
}

Example Code Implementations

Below are example implementations in various programming environments.


cURL

curl --location 'https://geolocation.divineapi.com/location' \
--header 'Authorization: Bearer {YOUR_AUTH_TOKEN}' \
--form 'api_key="{YOUR_API_KEY}"' \
--form 'place="beg"'
curl -X POST "https://geolocation.divineapi.com/location" \
  -H "Authorization: Bearer {Your Auth Token}" \
  --form 'api_key="{Your API Key}"' \
  --form 'place="beg"'
const FormData = require('form-data');
const axios = require('axios');

const form = new FormData();
form.append('api_key', '{Your API Key}');
form.append('place', 'beg');

const response = await axios.post('https://geolocation.divineapi.com/location', form, {
  headers: {
    ...form.getHeaders(),
    'Authorization': 'Bearer {Your Auth Token}',
  }
});

console.log(response.data);
import requests

url = "https://geolocation.divineapi.com/location"
headers = {
    "Authorization": "Bearer {Your Auth Token}",
}
payload = {
    "api_key": "{Your API Key}",
    "place": "beg",
}

response = requests.post(url, headers=headers, data=payload)

print(response.json())
const formData = new FormData();
formData.append('api_key', '{Your API Key}');
formData.append('place', 'beg');

const response = await fetch('https://geolocation.divineapi.com/location', {
  method: 'POST',
  headers: {
      'Authorization': "Bearer {Your Auth Token}",
    },
  body: formData,
});

const data = await response.json();
console.log(data);
<?php

use GuzzleHttp\Client;

$client = new Client();

$response = $client->request('POST', 'https://geolocation.divineapi.com/location', [
    'headers' => [
        'Authorization' => 'Bearer {Your Auth Token}',
    ],
    'multipart' => [
        ['name' => 'api_key', 'contents' => '{Your API Key}'],
        ['name' => 'place', 'contents' => 'beg'],
    ],
]);

echo $response->getBody();
package main

import (
    "bytes"
    "fmt"
    "mime/multipart"
    "net/http"
    "io"
)

func main() {
    body := &bytes.Buffer{}
    writer := multipart.NewWriter(body)
    writer.WriteField("api_key", "{Your API Key}")
    writer.WriteField("place", "beg")
    writer.Close()

    req, _ := http.NewRequest("POST", "https://geolocation.divineapi.com/location", body)
    req.Header.Set("Content-Type", writer.FormDataContentType())
    req.Header.Set("Authorization", "Bearer {Your Auth Token}")

    client := &http.Client{}
    resp, _ := client.Do(req)
    defer resp.Body.Close()

    body2, _ := io.ReadAll(resp.Body)
    fmt.Println(string(body2))
}
import okhttp3.*;
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        OkHttpClient client = new OkHttpClient();

        RequestBody body = new MultipartBody.Builder()
            .setType(MultipartBody.FORM)
            .addFormDataPart("api_key", "{Your API Key}")
            .addFormDataPart("place", "beg")
            .build();

        Request request = new Request.Builder()
            .url("https://geolocation.divineapi.com/location")
            .post(body)
            .addHeader("Authorization", "Bearer {Your Auth Token}")
            .build();

        Response response = client.newCall(request).execute();
        System.out.println(response.body().string());
    }
}
import Foundation

let url = URL(string: "https://geolocation.divineapi.com/location")!
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("Bearer {Your Auth Token}", forHTTPHeaderField: "Authorization")

let boundary = "Boundary-\(UUID().uuidString)"
request.setValue("multipart/form-data; boundary=\(boundary)", forHTTPHeaderField: "Content-Type")

var bodyData = Data()
bodyData.append("--\(boundary)\r\n".data(using: .utf8)!)
bodyData.append("Content-Disposition: form-data; name=\"api_key\"\r\n\r\n".data(using: .utf8)!)
bodyData.append("{Your API Key}\r\n".data(using: .utf8)!)
bodyData.append("--\(boundary)\r\n".data(using: .utf8)!)
bodyData.append("Content-Disposition: form-data; name=\"place\"\r\n\r\n".data(using: .utf8)!)
bodyData.append("beg\r\n".data(using: .utf8)!)
bodyData.append("--\(boundary)--\r\n".data(using: .utf8)!)
request.httpBody = bodyData

let task = URLSession.shared.dataTask(with: request) { data, response, error in
    if let data = data {
        print(String(data: data, encoding: .utf8) ?? "")
    }
}
task.resume()
import okhttp3.*

fun main() {
    val client = OkHttpClient()

    val body = MultipartBody.Builder()
        .setType(MultipartBody.FORM)
        .addFormDataPart("api_key", "{Your API Key}")
        .addFormDataPart("place", "beg")
        .build()

    val request = Request.Builder()
        .url("https://geolocation.divineapi.com/location")
        .post(body!!)
        .addHeader("Authorization", "Bearer {Your Auth Token}")
        .build()

    client.newCall(request).execute().use { response ->
        println(response.body?.string())
    }
}
using System;
using System.Net.Http;
using System.Threading.Tasks;

class Program {
    static async Task Main() {
        using var client = new HttpClient();
        client.DefaultRequestHeaders.Add("Authorization", "Bearer {Your Auth Token}");

        var content = new MultipartFormDataContent();
        content.Add(new StringContent("{Your API Key}"), "api_key");
        content.Add(new StringContent("beg"), "place");

        var response = await client.PostAsync("https://geolocation.divineapi.com/location", content);
        var result = await response.Content.ReadAsStringAsync();
        Console.WriteLine(result);
    }
}
Response 200
{
    "status": "success",
    "code": 200,
    "message": "Request successful",
    "data": {
        "count": 10,
        "query": "patna",
        "results": [
            {
                "place_id": 1260091,
                "name": "Patna",
                "full_name": "Patna, Bihar, India",
                "country": "IN",
                "admin1": "Bihar",
                "latitude": 25.41667,
                "longitude": 85.16667,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 5838465
            },
            {
                "place_id": 12685607,
                "name": "Patna Rural",
                "full_name": "Patna Rural, Bihar, India",
                "country": "IN",
                "admin1": "Bihar",
                "latitude": 25.58486,
                "longitude": 85.16871,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 1771140
            },
            {
                "place_id": 1260086,
                "name": "Patna",
                "full_name": "Patna, Bihar, India",
                "country": "IN",
                "admin1": "Bihar",
                "latitude": 25.59408,
                "longitude": 85.13563,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 1684297
            },
            {
                "place_id": 12683334,
                "name": "Patnagarh",
                "full_name": "Patnagarh, Odisha, India",
                "country": "IN",
                "admin1": "Odisha",
                "latitude": 20.76025,
                "longitude": 83.11076,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 168325
            },
            {
                "place_id": 1260082,
                "name": "Patnāgarh",
                "full_name": "Patnāgarh, Odisha, India",
                "country": "IN",
                "admin1": "Odisha",
                "latitude": 20.70833,
                "longitude": 83.13263,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 21024
            },
            {
                "place_id": 1694370,
                "name": "Patnanungan",
                "full_name": "Patnanungan, Calabarzon, Philippines",
                "country": "PH",
                "admin1": "Calabarzon",
                "latitude": 14.81667,
                "longitude": 122.15,
                "timezone": "Asia/Manila",
                "timezone_value": 8,
                "population": 15554
            },
            {
                "place_id": 1694369,
                "name": "Patnanungan",
                "full_name": "Patnanungan, Calabarzon, Philippines",
                "country": "PH",
                "admin1": "Calabarzon",
                "latitude": 14.78333,
                "longitude": 122.18333,
                "timezone": "Asia/Manila",
                "timezone_value": 8,
                "population": 6901
            },
            {
                "place_id": 2640574,
                "name": "Patna",
                "full_name": "Patna, Scotland, United Kingdom",
                "country": "GB",
                "admin1": "Scotland",
                "latitude": 55.36406,
                "longitude": -4.50594,
                "timezone": "Europe/London",
                "timezone_value": 0,
                "population": 2190
            },
            {
                "place_id": 10532578,
                "name": "Patna",
                "full_name": "Patna, Madhya Pradesh, India",
                "country": "IN",
                "admin1": "Madhya Pradesh",
                "latitude": 24.52205,
                "longitude": 81.52903,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 0
            },
            {
                "place_id": 10457447,
                "name": "Patna",
                "full_name": "Patna, Madhya Pradesh, India",
                "country": "IN",
                "admin1": "Madhya Pradesh",
                "latitude": 23.56601,
                "longitude": 79.85514,
                "timezone": "Asia/Kolkata",
                "timezone_value": 5.5,
                "population": 0
            }
        ]
    },
    "attribution": "Place data © GeoNames (geonames.org), CC BY 4.0"
}