Showing posts with label latitude. Show all posts
Showing posts with label latitude. Show all posts

Thursday, 4 September 2014

To Calculate distance between two latitude & longitude in php

Method I :

function distance($lat1, $lon1, $lat2, $lon2, $unit) {

  $theta = $lon1 - $lon2;
  $dist = sin(deg2rad($lat1))*sin(deg2rad($lat2))+
cos(deg2rad($lat1))*cos(deg2rad($lat2))*cos(deg2rad($theta));
  $dist = acos($dist);
  $dist = rad2deg($dist);
  $miles = $dist * 60 * 1.1515;
  $unit = strtoupper($unit);

  if ($unit == "K") {
    return ($miles * 1.609344);
  } else if ($unit == "N") {
      return ($miles * 0.8684);
    } else {
        return $miles;
      }
}

echo distance(11.01078,76.93433,11.14137,78.59412,10.1, "M") . " Miles
"; echo distance(11.01078,76.93433,11.14137,78.59412,10.1, "K") . " Kilometers
"; echo distance(11.01078,76.93433,11.14137,78.59412,10.1, "N") . " Nautical Miles
"; Method II: function calculateDistance($latitude1, $longitude1, $latitude2, $longitude2) { $theta = $longitude1 - $longitude2; $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta))); $miles = acos($miles); $miles = rad2deg($miles); $miles = $miles * 60 * 1.1515; return $miles; }

Wednesday, 6 August 2014

Get address by using lattitude and longitude Google APi

<?php

echo getAddress("28.6100", "77.2300");

function getaddress($lat,$lng)
{
$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")
return $data->results[0]->formatted_address;
else
return false;
}
?>

Friday, 18 July 2014

How to get IP based country,state,currency and countrycode and Internet connection Provider and lattitude & longitude in PHP?

<?php
echo getipaddress();
function getipaddress(){
   $xml = simplexml_load_file("http://www.geoplugin.net/xml.gp?ip=".getRealIpAddr());
   print_r($xml);
   $ccode=$xml->geoplugin_countryCode;
   return $ccode;
}
function getRealIpAddr(){
   if (!empty($_SERVER['HTTP_CLIENT_IP']))  
   {
  $ip=$_SERVER['HTTP_CLIENT_IP'];
 }elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))  
 {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
 }else{
  $ip=$_SERVER['REMOTE_ADDR'];
 }
 //$ip="YOUR IP";
 return $ip;
}
   
echo "<hr>";
$details = ip_details(getRealIpAddr());
print_r($details);

function ip_details($ip) {
    $json = file_get_contents("http://ipinfo.io/{$ip}");
    $details = json_decode($json);
    return $details;
}


?>

Friday, 11 April 2014

Get Latitdue and longitude from google map

Code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="http://maps.google.com/maps?file=api&v=2&key=" type="text/javascript"></script>
<script type="text/javascript">
$( document ).ready(function() {
 $("#map").show();
 show_popup();
});


function show_popup(){
 $("#map").show();
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
var center = new GLatLng(11.00, 78.00);
map.setCenter(center, 7);
geocoder = new GClientGeocoder();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").value = center.lat().toFixed(5);
document.getElementById("lng").value = center.lng().toFixed(5);

GEvent.addListener(marker, "dragend", function() {
var point = marker.getPoint();
map.panTo(point);
document.getElementById("lat").value = point.lat().toFixed(5);
document.getElementById("lng").value = point.lng().toFixed(5);
});

GEvent.addListener(map, "moveend", function() {
map.clearOverlays();
var center = map.getCenter();
var marker = new GMarker(center, {draggable: true});
map.addOverlay(marker);
document.getElementById("lat").value = center.lat().toFixed(5);
document.getElementById("lng").value = center.lng().toFixed(5);

GEvent.addListener(marker, "dragend", function() {
var point =marker.getPoint();
map.panTo(point);
document.getElementById("lat").value = point.lat().toFixed(5);
document.getElementById("lng").value = point.lng().toFixed(5);
});
});
}
}
</script>
<table align='center'>
<tr>
<td><label>Latitude</label></td>
<td><label>:</label></td>
<td><input type="text" name="latitude" id="lat" onclick="show_popup();" readonly value=""/>
<em></em>
</td>
<td><label>Longitude</label></td>
<td><label>:</label></td>
<td><input type="text" name="longitude" onclick="show_popup();" id="lng" readonly value=""/>
<em></em>
</td>
</tr>
<tr><td colspan='6'><div align="center" id="map" style="width:700px;height:450px;-webkit-border-radius: 18px 20px 20px 20px;-moz-border-radius: 18px 20px 20px 20px;border-radius: 18px 20px 20px 20px;border:2px solid #82B5CF;background:rgba(231,228,237,0.5);"></div></td></tr>
</table>

Wednesday, 24 April 2013

To get distance based on latitude & longitude calculate in Mysql query

SELECT DISTINCT ( a.categoryID ), a.categoryName, a.imgFile, MIN( 3959 * ACOS( COS( RADIANS( 11.0168445 ) ) * COS( RADIANS( c.lattitude ) ) * COS( RADIANS( c.longitude ) - RADIANS( 76.9558321 ) ) + SIN( RADIANS( 11.0168445 ) ) * SIN( RADIANS( 11.0168445 ) ) ) ) AS distance