Aspdotnet-Suresh

aspdotnet-suresh offers C#.net articles and tutorials,csharp dot net,asp.net articles and tutorials,VB.NET Articles,Gridview articles,code examples of asp.net 2.0 /3.5,AJAX,SQL Server Articles,examples of .net technologies

Javascript Get User IP Address, Latitude, Longitude, Country, City, State Details

Jan 24, 2013
Introduction

Here I will explain how to get user current location details IP address, country, city, state, latitude and longitude using smart-ip json url in JavaScript using asp.net in C#, VB.NET.

Description:
  
In previous articles I explained jQuery Shake image on mouse over, jQuery upload multiple files using multiple file upload plugin,
jQuery fancy switch on and off effects example and many articles relating to JavaScript, jQuery, asp.net. Now I will explain how to get current user location details IP address, country, city, state, latitude and longitude using smart-ip json url in JavaScript

To get current user location details I am using smart-ip.net json string to get all the information for that you need to write the following code


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Get User Details IP Address, city, country, state, latitude, longitude </title>
<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>
</head>
<body>
<div>
<table id="tbDetails" cellpadding="2" cellspacing="2" style=" border:1px solid #000; font-family:Verdana;" >
<tr style="background-color:#DC5807; color:White; font-weight:bold">
<td colspan="2" align="center">User Information</td>
</tr>
<tr style="border:solid 1px #000000">
<td align="right"><b>IP:</b></td>
<td><label id="lblIP"/></td>
</tr>
<tr>
<td align="right"><b>Country:</b></td>
<td><label id="lblCountry"/></td>
</tr>
<tr>
<td align="right"><b>City:</b></td>
<td><label id="lblCity"/></td>
</tr>
<tr>
<td align="right"><b>Region:</b></td>
<td><label id="lblregion"/></td>
</tr>
<tr>
<td align="right"><b>latitude:</b></td>
<td><label id="lbllatitude"/></td>
</tr>
<tr>
<td align="right"><b>Longitude:</b></td>
<td><label id="lbllongitude"/></td>
</tr>
<tr>
<td align="right"><b>Time Zone:</b></td>
<td><label id="lbltimezone"/></td>
</tr>
</table>
</div>
</body>
</html>
Live Demo

For live demo check below of your current location details


User Information
IP:
Country:
City:
Region:
latitude:
Longitude:
Time Zone:


If you enjoyed this post, please support the blog below. It's FREE!

Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email.

subscribe by rss Subscribe by RSS subscribe by email Subscribe by Email

25 comments :

Unknown said...

Hi sir,I got ur model but i am getting your code IP address but i need my system IP address...how can we get that??Plzz reply

Peter said...

My geo location wasn't right...

MUTHU KUMAR.R said...

Hi Sir,I have Create one module(VB.NET),I need EXE file,In My Application 2 Exe are there,I don't know Which file is correct one?
1.Module name-BIN-DEBUG-EXE
2.Module name-OBJ-DEBUG-EXE

At the same time need to implement in Another Server(It's Located other branch of our Organization,They have Diff Server)I changed that server name as destination server name,But It Shows an Error like-------A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server),,
Plz Advice How to solve..

Unknown said...

not get current location display only which show like above demo

Lalit said...

not showing right info

Suresh Dasari said...

@all...
Above one showing information correct only if you think that is showing wrong info check your details ip2location some other services also i hope everything will return same info.....

Suchith said...

Hi sir
i refered your previous post to display google map in aspx page,but is there any way to search the location based on the location input by text box..thanks

Suchith said...
This comment has been removed by the author.
VISHAL AGRAWAL said...

hi sir,

I want a function that return Address as a string by latitude & longitude

Anonymous said...

all fields showing unidentified...

Unknown said...

Bravo,,U R Simply Awesome

Unknown said...

Hello,

I added above code in my web application, but assigned labeled values not getting on server side what's the issue ? please guide me

Ravi said...

Hi Sir,i need reginalzone address based on longitude and lattitude.pls tell me

Anonymous said...

not correct info

Anonymous said...

I want application which can trace current cell phone location

Abhinavsingh993 said...

Great sir, it's working

Unknown said...

its showing the same details only not the current user details..plz help me out

Anonymous said...

i need to get zipcode. can u pls help me?

Unknown said...

hi

In my page jquery slider is running after i refresh the page jquery slider loading some late

because in my page smart-ip.net link is runing,
smart-ip.net link is completed the action after jquery running correctly before it's not loading how to solve this one

Unknown said...

Can you please put a downloadable sample

Top 500 Websites said...

I had added it in my site but most things in my site stopped. I don't know why and that make me sad and i removed it again. I'm looking for sample script show IP address, Can you help me ?

Unknown said...

how to pass the javascript values to server side

Unknown said...

this code can not open in IE .Please any one help me how to run this code in any IE.

Unknown said...

Not working

Anonymous said...

Not showing any info - Just showing undefined as Demo

Give your Valuable Comments

Note: Only a member of this blog may post a comment.

© 2015 Aspdotnet-Suresh.com. All Rights Reserved.
The content is copyrighted to Suresh Dasari and may not be reproduced on other websites without permission from the owner.