IP to Location using Javascript
<script type="application/javascript">
function getip(json){
alert(json.ip); // alerts the ip address
}
</script>
<script type="application/javascript" src="http://jsonip.appspot.com/?callback=getip"></script>
I can get User IP by this code...
I want to find location of this IP. How can I?
You can submit the IP you receive to an online geolocation service, such as http://www.geoplugin.net/json.gp?ip=<your ip here>&jsoncallback=<suitable javascript function in your source>
, then including the source it returns which will run the function you specify in jsoncallback
with the geolocation information.
Alternatively, you may want to look into HTML5's geolocation features -- you can see a demo of it in action here. The advantage of this is that you do not need to make requests to foreign servers, but it may not work on browsers that do not support HTML5.
A free open source community run geolocation ip service that runs on the MaxMind database is available here: https://ipstack.com/
Example
https://api.ipstack.com/160.39.144.19
Limitation
10,000 queries per month