I'm looking for a less complicated way to get user coordinates. please have a look at my example below. I'm trying by all means to avoid using IP address as they do not give me the correct address information.
$lat = "-25.702064";//I need to replace these hard coded coordinates by ones I've picked up automatically.
$lng = " 28.263665";
$url = 'http://maps.googleapis.com/maps/api/geocode/json?latlng='.trim($lat).','.trim($lng).'&sensor=false';
$json = @file_get_contents($url);
$data=json_decode($json);
$status = $data->status;
if($status=="OK")
{
$address = $data->results[0]->formatted_address;
$addr = explode(",",$address);
echo "Street :".$addr[0]."<br>";
echo "Suburb :".$addr[1]."<br>";
echo "Region :".$addr[2]."<br>";
echo "Postal code :".$addr[3]."<br>";
echo "Country :".$addr[4]."<br>";
}
else
{
//return false;
echo "No available data to display about address";
}