Thursday, 20 March 2014

Filled Under:

how to get latitude and longitude from address in php

              you can easily find latitude and longitude using i am using Google Maps API to get latitude & longitude using php.just copy below code and run this code to you can easily find latitude or longitude of any address in the world.

HTML Code :

<br />
    <form name="frm" id="frm" method="post" enctype="multipart/form-data" action="get_lati_longi.php">
        Type Your Location : <input type="text" name="myaddress" />
        <input type="submit" value="get lati longi">
<br />

PHP Code :


$myaddress = urlencode($_POST['myaddress']);
$url = "$myaddress&sensor=false";
$getmap = file_get_contents($url); 
$googlemap = json_decode($getmap);

foreach($googlemap->results as $res){
     $address = $res->geometry;
     $latlng = $address->location;
     $formattedaddress = $res->formatted_address;

echo "Latitude: ". $latlng->lat ."<br />". "Longitude:". $latlng->lng;