Friday, April 19, 2013

Get County from User Lat Long

In Mobile application how the server knows about the posted device country and response then as per the location.

Get the current location of the device and use google map api to get user location. Get location from the ipaddress is a worth thing now. because all the internet user use proxy network.

PHP:

<?php

$cur_lat =$_REQUEST['lat'];
$cur_lon = $_REQUEST['lon'];


$geocode=file_get_contents('http://maps.googleapis.com/maps/api/geocode/json?latlng='.$cur_lat.','.$cur_lon.'&sensor=false');
$output= json_decode($geocode);

for($j=0;$j<count($output->results[0]->address_components);$j++){
        $country = $output->results[0]->address_components[$j]->short_name;
}

echo $country;

<?php>

Yup... You get the country id..

No comments:

Post a Comment