Get Full Address From Latitude Longitude Google Map API In PHP

  • 29-07-2022
  • 951
  • PHP
  • Haresh Chauhan

Get address from latitude and longitude using google map API in PHP; In this post, I will send lat long to google map API params and will receive the address from API response.

To get an address from lat long using PHP we will fire a google map API and collect all the information about the location from the API what is except the address.

At the end of this post, you will easy to get an address from the lat long in PHP with the help of google Maps API. Here "API KEY" must be required to get data. So first go to "GOOGLE DEVELOPER" and "ENABLE" google Maps API and generate the API key from there. Once you get the API put in this example and send let long to this function. The function will return the full address form if the valid latitude and longitude given.

Get Zipcode/Pincode From Latitude and Longitude PHP and Google Maps API

Here I have made an example function, This function must require two arguments and these two arguments are latitude and longitude. Call the function and pass the argument and this function will return its full address of it.

<?php

function getaddress($lat,$lng)
{
    $url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($lng).'&key={YOUR API KEY}';
    
    $json = @file_get_contents($url);

    $data = json_decode($json);

    $status = $data->status;

    if($status == "OK"){

        return $data->results[0]->formatted_address;
    }else{

        return false;
    }
}

print_r(getaddress('22.1723','71.6636'));

?>

We always thanks to you for reading our blogs.


dharmesh-image

Dharmesh Chauhan

(Swapinfoway Founder)

Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us

haresh-image

Haresh Chauhan

(Co-Founder)


We Are Also Recommending You :