How to Reverse Geocode Latitude, Longitude into an Address in PHP

Cloudmersive
2 min readFeb 24, 2023

--

Just as text street address data can be algorithmically translated into coordinates, latitude and longitude values can also be used to retrieve street addresses — you just need the right API to do it. The Reverse Geocoding API provided below is free-to-use and will return structured address information (including street address, city, state/province, postal code, etc.) based on latitude and longitude values provided in the input request.

Of course, this API will only return as much information as is available for each set of coordinates — locations in the middle of the Pacific Ocean, for example, are unlikely to return an associated street address or zip code.

To structure your API call, start by installing the SDK with this command:

composer require cloudmersive/cloudmersive_validate_api_client

After that, complete your call with the remaining code, and include an API key to authorize your request (get one for free by registering a free account):

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');



$apiInstance = new Swagger\Client\Api\AddressApi(


new GuzzleHttp\Client(),
$config
);
$input = new \Swagger\Client\Model\ReverseGeocodeAddressRequest(); // \Swagger\Client\Model\ReverseGeocodeAddressRequest | Input reverse geocoding request

try {
$result = $apiInstance->addressReverseGeocodeAddress($input);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling AddressApi->addressReverseGeocodeAddress: ', $e->getMessage(), PHP_EOL;
}
?>

That’s all the code you’ll need! You can refer to the following JSON example to structure your input request:

{
"Latitude": 0,
"Longitude": 0
}

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet