How to get Latitude and Longitude from Country or city using PHP


 


 
How to get latitude and longitude from address in php
 
You can use country name for get Latitude and Longitude and also use full address instead of city or country

$address = 'india';

Or also you can use CIty name for get Latitude and Longitude

$address = 'Junagadh';

Or you can also use city, state and Country togther.

$address = 'Junagadh+Gujarat+India';

There are two method for get Latitude and Longitude

First is :

$details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=".$address."&sensor=false";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $details_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = json_decode(curl_exec($ch), true);

// If Status Code is ZERO_RESULTS, OVER_QUERY_LIMIT, REQUEST_DENIED or INVALID_REQUEST
if ($response['status'] != 'OK') {
	return null;
}

//print_r($response);
//print_r($response['results'][0]['geometry']['location']);

$latLng = $response['results'][0]['geometry']['location'];

$lat = $latLng['lat'];
$lng = $latLng['lng'];	

OR
Second method is:

$geocode_stats = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?address=india&sensor=false");

$output_deals = json_decode($geocode_stats);

$latLng = $output_deals->results[0]->geometry->location;

$lat = $latLng->lat;
$lng = $latLng->lng;	

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

How to Get county name from latitude and longitude Using PHP


 
For get county name from latitude and longitude Using PHP

$geocode_stats = file_get_contents("http://maps.googleapis.com/maps/api/geocode/json?latlng=23.0333,72.6167&sensor=false");
$output_deals = json_decode($geocode_stats);
$country = $output_deals->results[2]->address_components[4]->long_name;

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

How to Get Current country name and latitude and longitude using Javascript


Get Current country name and latitude and longitude using Javascript

$.getJSON('http://smart-ip.net/geoip-json/?callback=?', function (data) {
    $("#hello").html('Latitude: ' + data.latitude +
        '<br /> Longitude: ' + data.longitude +
        '<br /> Country: ' + data.countryName);
});

<div id="hello"></div>

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya

How do i get User IP Address, Latitude, Longitude, Country, City, State Details


 


 
To get current user location details

Please copy below code.

<script src="http://code.jquery.com/jquery-1.8.2.js" type="text/javascript"></script>
<script type="text/javascript">
var strip, strcountry, strcity, strregion, strlatitude, strlongitude, strtimezone

function GetUserInfo(data) {
	strip = data.host; strcountry = data.countryName; strcity = data.city;
	strregion = data.region; strlatitude = data.latitude; strlongitude = data.longitude;
	strtimezone = data.timezone;
}
$(function () {
	BindUserInfo();
})
function BindUserInfo() {
	document.getElementById('lblIP').innerHTML = strip;
	document.getElementById('lblCountry').innerHTML = strcountry;
	document.getElementById('lblCity').innerHTML = strcity;
	document.getElementById('lblregion').innerHTML = strregion;
	document.getElementById('lbllatitude').innerHTML = strlatitude;
	document.getElementById('lbllongitude').innerHTML = strlongitude;
	document.getElementById('lbltimezone').innerHTML = strtimezone;
}
</script>
<script type="text/javascript" src="http://smart-ip.net/geoip-json?callback=GetUserInfo"></script>

Below is a HTML

<table id="tbDetails" cellpadding="2" cellspacing="2" style=" border:1px solid #000; font-family:Verdana;" >
	<tr style="background-color:#C; color:White; font-weight:bold">
		<td colspan="2" align="center">User Information</td>
	</tr>
	<tr style="border:solid 1px #000000">
		<td align="right">IP:</td>
		<td><label id="lblIP"/></td>
	</tr>
	<tr>
		<td align="right">Country:</td>
		<td><label id="lblCountry"/></td>
	</tr>
	<tr>
		<td align="right">City:</td>
		<td><label id="lblCity"/></td>
	</tr>
	<tr>
		<td align="right">Region:</td>
		<td><label id="lblregion"/></td>
	</tr>
	<tr>
		<td align="right">latitude:</td>
		<td><label id="lbllatitude"/></td>
	</tr>
	<tr>
		<td align="right">Longitude:</td>
		<td><label id="lbllongitude"/></td>
	</tr>
	<tr>
		<td align="right">Time Zone:</td>
		<td><label id="lbltimezone"/></td>
	</tr>
</table>

If you have any queries, please do not hesitate to contact me at Jainish Senjaliya