Overview

The bng2latlong API provides specialized geocoding and reverse geocoding functionalities tailored for the United Kingdom. It enables developers to convert various forms of UK location data, including British National Grid (BNG) references, UK postcodes, and standard latitude/longitude coordinates. This focus makes it suitable for applications requiring precise geographical data within the UK, such as logistics, mapping platforms, emergency services, and location-based marketing.

The service addresses the specific challenges of UK geospatial data, which includes handling the proprietary BNG system and the granular nature of UK postcodes. Developers can use the API to transform a UK postcode into its corresponding latitude and longitude, convert BNG eastings and northings into WGS84 coordinates, or perform reverse geocoding to find the nearest postcode from a given latitude and longitude. The API was founded in 2011 to serve this specific niche, offering a targeted solution for developers building UK-centric applications that require accurate and consistent location data. Its documentation includes examples in JavaScript, PHP, Python, Ruby, and cURL, facilitating integration into diverse development environments.

Use cases for the bng2latlong API extend to real estate platforms needing to display property locations accurately, delivery services optimizing routes within the UK, and government or public sector applications processing citizen data based on location. The API's dedication to UK-specific data types and formats differentiates it from more generalized global geocoding services. It supports both single and batch conversions, which can be useful for processing large datasets efficiently. The API structure is designed to be straightforward, providing clear endpoints for each conversion type, as detailed in the bng2latlong API documentation. With GDPR compliance, it also addresses data privacy considerations relevant for UK and EU operations.

Key features

  • Postcode to Latitude/Longitude Conversion: Converts full or partial UK postcodes into WGS84 latitude and longitude coordinates, suitable for mapping applications.
  • BNG to Latitude/Longitude Conversion: Translates British National Grid easting and northing coordinates into global WGS84 latitude and longitude. The British National Grid is the primary grid reference system used for maps in Great Britain by the Ordnance Survey, as described by Mozilla's BNG glossary entry.
  • Latitude/Longitude to Postcode Conversion: Performs reverse geocoding, identifying the nearest UK postcode or postal district from a given WGS84 latitude and longitude pair.
  • Geocoding API: General geocoding capabilities for UK addresses, providing coordinates from textual address inputs.
  • Reverse Geocoding API: Converts geographical coordinates back into human-readable locations, primarily focusing on UK postcodes and addresses.
  • Batch Processing: Supports processing multiple geocoding requests in a single API call for increased efficiency.
  • GDPR Compliant: Adheres to General Data Protection Regulation standards for data handling and privacy.
  • Developer-Friendly Documentation: Provides clear API references and code examples in multiple programming languages, including JavaScript integration examples.

Pricing

Pricing for the bng2latlong API is structured around daily and monthly request limits, with a free tier available for initial development and low-volume usage. As of May 2026, the details are as follows:

Plan Requests per Day (Free Tier) Requests per Month (Paid Tiers) Cost per Month
Free 500 N/A £0
Paid Tier 1 N/A 1,000,000 £20
Paid Tier 2 N/A 5,000,000 £50
Paid Tier 3 N/A 10,000,000 £90
Custom N/A > 10,000,000 Contact for quote

Additional details and current pricing can be found on the official bng2latlong pricing page.

Common integrations

  • Mapping Platforms: Integrate UK postcode and BNG conversions into mapping services like Google Maps or OpenStreetMap to display accurate UK locations.
  • Logistics and Delivery Systems: Enhance route optimization and delivery address validation for UK-based operations by converting postcodes to precise coordinates.
  • E-commerce Applications: Validate shipping addresses and provide location-based services for customers within the UK.
  • Real Estate Platforms: Accurately pinpoint property locations and search by postcode or BNG coordinates for UK properties.
  • CRM and ERP Systems: Enrich customer and operational data with precise UK geographical information.
  • Data Analytics Tools: Incorporate UK location data into business intelligence and reporting for regional analysis.

Alternatives

  • Postcodes.io: A free and open-source API focused specifically on UK postcode data, offering validation, lookup, and nearest postcode functionalities.
  • OpenCage Geocoding API: A global geocoding service that also supports UK specific data, offering forward and reverse geocoding with a focus on open data sources, as highlighted in their OpenCage API documentation.
  • Geolocator (UK): Another UK-specific geocoding service offering postcode and address lookup services.

Getting started

To begin using the bng2latlong API, you typically make a simple HTTP GET request to the appropriate endpoint with your API key and the coordinates or postcode you wish to convert. The following JavaScript example demonstrates how to convert a UK postcode to latitude and longitude coordinates. This example assumes you have an API key and are making a request from a client-side JavaScript environment or a Node.js server.


const apiKey = 'YOUR_API_KEY'; // Replace with your actual API key
const postcode = 'SW1A 0AA'; // Example: Buckingham Palace postcode

async function getCoordinatesFromPostcode(postcode, key) {
  const url = `https://www.bng2latlong.co.uk/api/postcode/${encodeURIComponent(postcode)}?key=${key}`;

  try {
    const response = await fetch(url);
    if (!response.ok) {
      if (response.status === 404) {
        throw new Error('Postcode not found or invalid.');
      } else if (response.status === 401) {
        throw new Error('Unauthorized: Invalid API key.');
      } else {
        throw new Error(`HTTP error! status: ${response.status}`);
      }
    }
    const data = await response.json();
    console.log(`Postcode: ${postcode}`);
    console.log(`Latitude: ${data.latitude}`);
    console.log(`Longitude: ${data.longitude}`);
  } catch (error) {
    console.error('Error fetching postcode coordinates:', error.message);
  }
}

getCoordinatesFromPostcode(postcode, apiKey);

/* Example of BNG to Lat/Long conversion (conceptual):
async function convertBngToLatLong(easting, northing, key) {
  const url = `https://www.bng2latlong.co.uk/api/bng/${easting}/${northing}?key=${key}`;
  try {
    const response = await fetch(url);
    const data = await response.json();
    console.log(`BNG Easting: ${easting}, Northing: ${northing}`);
    console.log(`Latitude: ${data.latitude}`);
    console.log(`Longitude: ${data.longitude}`);
  } catch (error) {
    console.error('Error converting BNG:', error);
  }
}
// convertBngToLatLong(532500, 180500, apiKey); // Example BNG for central London
*/

This JavaScript code snippet demonstrates how to send an asynchronous request to the bng2latlong API's postcode endpoint. It uses fetch to retrieve the latitude and longitude for a specified UK postcode, includes basic error handling for common API response issues like invalid postcodes or API keys, and logs the results to the console. For a complete list of endpoints and detailed usage instructions, refer to the bng2latlong API documentation.