Developers

Code Samples

Copy-ready examples for every endpoint — forward and reverse geocoding, autocomplete, geoparsing, address parsing and elevation — in the language you already use. Replace YOUR_API_KEY with the key from your dashboard.

Accessing Geocodify's APIs with JavaScript and Node.js

Geocodify offers a suite of powerful geocoding services, and integrating these services into your JavaScript or Node.js application can greatly enhance its capabilities. Here’s a guide on how to access all six endpoints offered by Geocodify: Forward Geocoding, Reverse Geocoding, Auto Complete, Geoparsing, Address Parsing, and Elevation.

Prerequisites

  • Node.js installed on your system.
  • An API key from Geocodify.

1. Setting Up Your Project

First, create a new Node.js project and install the axios package for making HTTP requests:

bash
mkdir geocodify-demo
cd geocodify-demo
npm init -y
npm install axios

2. Accessing Geocodify's APIs

Forward Geocoding

Converts addresses into geographic coordinates (latitude and longitude).

javascript
const axios = require('axios');

const forwardGeocode = async (address) => {
    try {
        const response = await axios.get(`https://api.geocodify.com/v2/geocode?api_key=YOUR_API_KEY&q=${address}`);
        console.log(response.data);
    } catch (error) {
        console.error(error);
    }
};

forwardGeocode("900 Boston Post Road, Guilford Center, CT, USA");

Reverse Geocoding

Converts geographic coordinates into a human-readable address.

javascript
const reverseGeocode = async (lat, lng) => {
    try {
        const response = await axios.get(`https://api.geocodify.com/v2/reverse?api_key=YOUR_API_KEY&lat=${lat}&lng=${lng}`);
        console.log(response.data);
    } catch (error) {
        console.error(error);
    }
};

reverseGeocode(40.6892, -74.0445);

Auto Complete

Provides address suggestions while the user types.

javascript
const autoComplete = async (query) => {
    try {
        const response = await axios.get(`https://api.geocodify.com/v2/autocomplete?api_key=YOUR_API_KEY&q=${query}`);
        console.log(response.data);
    } catch (error) {
        console.error(error);
    }
};

autoComplete("900 Boston Post Road, Guilford Center, CT, USA");

Geoparsing

Extracts location data from unstructured text.

javascript
const geoparse = async (text) => {
    try {
        const response = await axios.get(`https://api.geocodify.com/v2/geoparse?api_key=YOUR_API_KEY&text=${encodeURIComponent(text)}`);
        console.log(response.data);
    } catch (error) {
        console.error(error);
    }
};

geoparse("I'm taking the 6AM out of New York, landing at 9am in LA and from there hopping onto a connecting flight to Sydney, Australia.");

Address Parsing

Breaks down a full address into its component parts.

javascript
const parseAddress = async (address) => {
    try {
        const response = await axios.get(`https://api.geocodify.com/v2/parse?api_key=YOUR_API_KEY&address=${address}`);
        console.log(response.data);
    } catch (error) {
        console.error(error);
    }
};

parseAddress("900 Boston Post Road, Guilford Center, CT, USA");

Elevation

Provides the elevation of a given latitude and longitude.

javascript
const getElevation = async (lat, lng) => {
    try {
        const response = await axios.get(`https://api.geocodify.com/v2/elevation?api_key=YOUR_API_KEY&lat=${lat}&lng=${lng}`);
        console.log(response.data);
    } catch (error) {
        console.error(error);
    }
};

getElevation(40.6892, -74.0445);

Looking for the full parameter reference and response formats? Read the API documentation. Questions about an example? Email us.