How to get geolocation in javascript

Wednesday 08th, Nov, 2017 | #HTML 5 #Ajax #Plugins


Geolocation using Ipinfo.io API

 

Ipinfo.io is a free (for the first 1,000 requests per day) IP information web service providing geolocation, hostname, organization and other data types. The ipinfo.io API returns a JSON response containing data fields describing the specified IP. The API supports JSONP callbacks and can provide additional information through a paid service, such as proxy detection, scraping prevention, and improved geolocation accuracy.

 


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

        <title>Documento sin título</title>

        <script src="https://code.jquery.com/jquery-3.2.1.js"></script>

        <script type="text/javascript">

        	function getGeo(){

	        	$.get("https://ipinfo.io/json", function (response) {

	        		console.log(response);

	        	});	

        	}

        </script>

    </head>

	<body onload="getGeo()">

	</body>

</html>