Find a geolocation of an IP address including latitude, longitude, city, region and country. Compare the data from multiple IP location providers.

This is also part of the Awesome Functions js library

PHP Code

<?php

 $ip = $_SERVER['REMOTE_ADDR']; 

 $content = file_get_contents("https://apimk.com/ip/get/".$ip);

 $json = json_decode($content, true);

 //Output all the data results

 //var_dump($json);

 //Output only few results

 $lon = $json['lon'];

 $lat = $json['lat'];

 $city = $json['city'];

 $state = $json['state'];

?>

Jquery Code

 <script type="application/javascript" src="jquery.min.js"></script>
 
 <script type="application/javascript">
 $(document).ready(function()
 {
   $.getJSON("https://apimk.com/ip.json", function(data, status)
   { 
     var d1 = JSON.stringify(data, null,2)
     console.log(d1)
  });
 });
 </script>

Result - JSON