SDKs overview

GeoApi offers a suite of APIs designed for geospatial services, including geocoding, place search, routing, and map rendering. To simplify integration for developers, GeoApi provides an official JavaScript SDK. This SDK encapsulates the complexities of direct API requests, offering a more streamlined approach for web-based projects. While the official offering is concentrated on JavaScript, the open nature of web APIs also allows for community-driven libraries and direct API consumption across various programming languages. The primary benefit of using an SDK is to reduce boilerplate code and handle common tasks such as authentication and request formatting, allowing developers to focus on application logic rather than the underlying API mechanics.

Integrating GeoApi services via an SDK or client library enables applications to incorporate location-based functionalities efficiently. This includes displaying interactive maps, validating addresses, finding points of interest, or calculating optimal routes. The choice between using an official SDK, a community library, or direct API calls often depends on the specific project requirements, the target programming environment, and the level of control a developer needs over the API interaction. GeoApi's comprehensive documentation provides detailed guides for all integration methods, including specific examples for different API endpoints.

Official SDKs by language

GeoApi officially supports a dedicated JavaScript SDK, tailored for web development environments. This SDK is designed to simplify the process of integrating GeoApi's services, such as the Geocoding API and Places API, into client-side applications. The SDK abstracts many of the underlying HTTP requests and response parsing, providing a more developer-friendly interface.

Language Package/Library Name Installation Command Maturity
JavaScript @geoapify/geocoder-autocomplete npm install @geoapify/geocoder-autocomplete or yarn add @geoapify/geocoder-autocomplete Official, Stable
JavaScript @geoapify/react-geocoder-autocomplete npm install @geoapify/react-geocoder-autocomplete or yarn add @geoapify/react-geocoder-autocomplete Official, Stable (React specific)
JavaScript @geoapify/leaflet-address-autocomplete npm install @geoapify/leaflet-address-autocomplete or yarn add @geoapify/leaflet-address-autocomplete Official, Stable (Leaflet specific)

For detailed usage and additional official packages, developers can refer to the official GeoApi Autocomplete documentation. These packages are actively maintained by GeoApi, ensuring compatibility and access to the latest features. The availability of framework-specific packages, such as for React and Leaflet, further streamlines integration into common web development stacks.

Installation

Installation for GeoApi's official JavaScript SDKs typically involves using a package manager like npm or Yarn, which are standard tools in modern JavaScript development workflows. The specific package you install depends on the desired functionality and your project's framework. For general address autocomplete functionality, the @geoapify/geocoder-autocomplete package is recommended. If you are working within a React project, @geoapify/react-geocoder-autocomplete provides React components for easier integration. Similarly, for projects utilizing the Leaflet mapping library, @geoapify/leaflet-address-autocomplete offers Leaflet-specific components.

To install the core GeoApi Geocoder Autocomplete package:

npm install @geoapify/geocoder-autocomplete

or

yarn add @geoapify/geocoder-autocomplete

For React projects, install the React-specific package:

npm install @geoapify/react-geocoder-autocomplete

or

yarn add @geoapify/react-geocoder-autocomplete

For Leaflet-integrated projects, use the Leaflet-specific package:

npm install @geoapify/leaflet-address-autocomplete

or

yarn add @geoapify/leaflet-address-autocomplete

After installation, you can import the necessary modules into your JavaScript or TypeScript files. These packages manage API requests, response handling, and provide UI components where applicable, significantly reducing the amount of manual coding required. For detailed installation instructions and dependency requirements, consult the specific package documentation within the GeoApi developer documentation.

Quickstart example

This quickstart example demonstrates how to integrate the @geoapify/geocoder-autocomplete package into a basic web application to provide address autocomplete functionality. This example assumes you have already installed the package using npm or Yarn, as detailed in the Installation section. You will need a GeoApi API key, which can be obtained by signing up on the GeoApi website.

HTML Structure (index.html)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>GeoApi Autocomplete Quickstart</title>
    <link rel="stylesheet" href="style.css">
</head>
<body>
    <div class="container">
        <h1>GeoApi Address Autocomplete</h1>
        <input type="text" id="autocomplete-input" placeholder="Enter an address...">
        <div id="autocomplete-container"></div>
    </div>
    <script src="app.js"></script>
</body>
</html>

CSS (style.css)

body {
    font-family: sans-serif;
    margin: 20px;
    background-color: #f4f4f4;
}
.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    background-color: #fff;
    border-radius: 8px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
    text-align: center;
    color: #333;
}
#autocomplete-input {
    width: 100%;
    padding: 10px;
    margin-bottom: 15px;
    border: 1px solid #ddd;
    border-radius: 4px;
    box-sizing: border-box;
}
#autocomplete-container {
    border: 1px solid #eee;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
}
.geoapify-autocomplete-items {
    cursor: pointer;
    padding: 10px;
    border-bottom: 1px solid #eee;
}
.geoapify-autocomplete-items:hover {
    background-color: #f1f1f1;
}
.geoapify-autocomplete-active {
    background-color: #e9e9e9;
}

JavaScript (app.js)

import { GeoapifyGeocoderAutocomplete } from '@geoapify/geocoder-autocomplete';

const API_KEY = 'YOUR_GEOAPIFY_API_KEY'; // Replace with your actual GeoApi API key

const autocomplete = new GeoapifyGeocoderAutocomplete(
    document.getElementById('autocomplete-container'),
    API_KEY,
    {
        /* Optional: Add options here, e.g., type: 'city' */
    }
);

autocomplete.on('select', (location) => {
    console.log('Selected location:', location);
    document.getElementById('autocomplete-input').value = location.properties.formatted;
});

autocomplete.on('suggestions', (suggestions) => {
    console.log('Suggestions:', suggestions);
});

// Integrate with the input element
document.getElementById('autocomplete-input').addEventListener('input', (event) => {
    autocomplete.input(event.target.value);
});

To run this example, save the HTML, CSS, and JavaScript files in the same directory. Ensure you replace 'YOUR_GEOAPIFY_API_KEY' with your actual GeoApi key. You will also need a local development server or a tool like Webpack/Rollup to handle the ES module import in app.js, as direct browser loading of ES modules from local files can have security restrictions or require specific server configurations. A simple way to serve this locally is by using npx serve in your project directory.

This setup creates an input field that suggests addresses as the user types, powered by GeoApi. When a suggestion is selected, its details are logged to the console, and the input field is updated with the formatted address. For more advanced configurations and event handling, refer to the Geoapify Geocoder Autocomplete documentation.

Community libraries

While GeoApi provides official SDKs primarily for JavaScript, the open and well-documented nature of its APIs allows for the development of community-contributed libraries and integrations across various programming languages. These libraries are typically developed and maintained by individual developers or organizations outside of GeoApi. They often aim to provide language-specific bindings, framework integrations, or specialized functionalities that complement the official offerings.

For example, developers frequently create wrappers for popular languages like Python, PHP, Ruby, or Java to interact with RESTful APIs. These wrappers often handle common tasks such as constructing API request URLs, setting headers (including authentication), and parsing JSON responses into native language objects. While a comprehensive list of all community libraries for GeoApi is not centrally maintained, platforms like GitHub are common repositories where developers can search for existing projects or contribute their own.

When considering a community library, it is advisable to evaluate its active maintenance, documentation, and community support. The quality and reliability of these libraries can vary significantly. Developers should also verify that the library supports the specific GeoApi endpoints and features required for their project. For direct API interaction in any language, GeoApi's API reference provides comprehensive details on request and response formats, enabling developers to build custom clients if a suitable community library is not available. This approach is consistent with common practices for integrating RESTful web services, where direct HTTP clients are often used when formal SDKs are absent or insufficient for specific needs.

Examples of how developers might interact with GeoApi in different languages without a dedicated SDK often involve standard HTTP client libraries. For instance, in Python, the requests library is commonly used to make HTTP calls. In Node.js (outside of the official browser-focused SDK), node-fetch or axios are popular choices. These direct integrations provide maximum flexibility but require the developer to handle aspects like API key management, error handling, and response parsing manually.