How to get user Latitude, Longitude & current address using PHP?

Today, We want to share with you php get current location latitude longitude.In this post we will show you php latitude longitude, hear for How to Find Position with HTML5 Geolocation? we will give you demo and example for implement.In this post, we will learn about get current location address in php with an example.

how to get latitude and longitude from form in php?

 function showPosition(position) {
  var get_informations = position.coords.latitude + "," + position.coords.longitude;

  var img_url = "


   document.getElementById("mapholder").innerHTML = "<img src='"+img_url+"'>";



<!DOCTYPE html>

<form method="post">
<input type="text" name="locations">
<input type="submit" name="submit" value="submit">


function getLatLong($locations){


        //Formatted locations

        $formattedAddr = str_replace(' ','+',$locations);

        //Send request and receive json data by locations

        $geocodeFromAddr = file_get_contents

        $output = json_decode($geocodeFromAddr);

        //Get latitude and longitute from json data

        $data['lat_cordinate']  = $output->responses[0]->geometry->location->lat; 

        $data['lang_cordinate'] = $output->responses[0]->geometry->location->lng;


            return $data;


            return false;



        return false;  


	$locations = $_POST['locations'];
	$latLong = getLatLong($locations);
	$lat_cordinate = $latLong['lat_cordinate']?$latLong['lat_cordinate']:' Sorry Not found';
	$lang_cordinate = $latLong['lang_cordinate']?$latLong['lang_cordinate']:'Sorry Not found';
	echo "Your Latitude:".$lat_cordinate."<br>";
	echo "Your lang_cordinate:".$lang_cordinate."";



I hope you get an idea about Get location from latitude and longitude in PHP.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.