Skip to content

Introduction to SmartMaps Geocoding

SmartMaps Geocoding is a powerful JavaScript library that enables the conversion of addresses into geographic coordinates (forward geocoding) and the translation of coordinates back into addresses (reverse geocoding). It provides an easy way to accurately visualize location data on a map and build location-based services.

Key Features

  • Forward Geocoding: Convert full or partial addresses into latitude and longitude coordinates. Simply provide an address string and receive the corresponding geographic coordinates.

  • Reverse Geocoding: Determine the address for a specific pair of coordinates. By providing latitude and longitude, reverse geocoding returns the associated address details such as street, house number, city, and postal code.

  • Extensive Address Database: SmartMaps Geocoding utilizes OpenStreetMap data a comprehensive, worldwide database of addresses and locations. The Geocoding API is minutely updated to ensure accurate results.

  • Flexible Data Format: Geocoding requests and responses support various formats including JSON and XML, allowing for seamless integration into your existing systems and applications.

Getting Started

To start using SmartMaps Geocoding:

  1. Sign up for a free account at SmartMaps to obtain your API key.

  2. Install the library via npm:

    npm install @smartmaps/geocoding
    
  3. Import the library into your project:

    import { Geocoder } from '@smartmaps/geocoding';
    
  4. Initialize the geocoder with your API key:

    const geocoder = new Geocoder('INSERT API-KEY');
    
  5. Use the geocoder to perform forward or reverse geocoding:

    // Forward geocoding
    const position = await geocoder.geocodeString('CAS-Weg 1, 76185 Karlsruhe');
    
    // Reverse geocoding
    navigator.geolocation.getCurrentPosition((currentPosition) => {
        const {
            coords: { latitude, longitude }
        } = currentPosition;
        geocoder.geocodeReverse({ lat: latitude, lng: longitude }).then((response) => {
            const address = response.features[0].properties;
            // Handle the retrieved address
        });
    });
    

Examples

Here are a few examples of how to use SmartMaps Geocoding:

  • Forward geocoding with a full address:

    const position = await geocoder.geocode({
        city: 'Karlsruhe',
        street: 'CAS Weg 1',
        zip: '76185'
    });
    
  • Reverse geocoding with coordinates:

    const address = await geocoder.geocodeReverse({ lat: 49.0068901, lng: 8.4037563 });
    

With SmartMaps Geocoding, you can easily integrate location-based functionality into your applications, enabling accurate visualization of locations on maps and providing enhanced user experiences.