Click here to Skip to main content
12,627,002 members (36,115 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

76.9K views
12 bookmarked
Posted

How to Find Current location based on IP-Address using Javascript?

, 6 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Sometime we have requirement to get current location e.g. Country code, country name etc using lat long. Though there are lot of way to accomplish this task but i found the easiest way to do this. And definitely its worth sharing as a tip and tricks.

The following javascript code is used to find the location, latitude and longitude based on your IP address
<script language="JavaScript" src="http://j.maxmind.com/app/geoip.js"></script>
 
<br>Country Code:
<script language="JavaScript">document.write(geoip_country_code());</script>
<br>Country Name:
<script language="JavaScript">document.write(geoip_country_name());</script>
<br>City:
<script language="JavaScript">document.write(geoip_city());</script>
<br>Region:
<script language="JavaScript">document.write(geoip_region());</script>
<br>Region Name:
<script language="JavaScript">document.write(geoip_region_name());</script>
<br>Latitude:
<script language="JavaScript">document.write(geoip_latitude());</script>
<br>Longitude:
<script language="JavaScript">document.write(geoip_longitude());</script>
<br>Postal Code:
<script language="JavaScript">document.write(geoip_postal_code());</script>


It displays your city name, latitude, longitude,country etc.
I hope you will like it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

maq_rohit
Technical Lead
United States United States
Rohit started Embedded Programing in his college days and now he is a Software Developer by Profession. Mainly he interested in cutting edge technology offer by Microsoft (i.e Azure,MVC). He Loves coding and his passion is always been towards Microsoft Technologies. Apart from coding his other hobbies include reading books and hang out with friends is his most favorite past time hobby.


1. 20 Apr 2014: Best Mobile Article of March 2014 - First Prize

You may also be interested in...

Pro
Pro

Comments and Discussions

 
Bugfor using a api Pin
Member 1206274616-Oct-15 20:49
memberMember 1206274616-Oct-15 20:49 
GeneralRe: for using a api Pin
maq_rohit2-Nov-15 10:22
professionalmaq_rohit2-Nov-15 10:22 
QuestionReferenceError: geoip_country_name is not defined Pin
Member 1163244922-Apr-15 0:53
memberMember 1163244922-Apr-15 0:53 
AnswerRe: ReferenceError: geoip_country_name is not defined Pin
maq_rohit a.k.a asthanarht5-May-15 14:50
professionalmaq_rohit a.k.a asthanarht5-May-15 14:50 
GeneralMy vote of 3 Pin
Anand_Mpec28-Dec-14 20:13
memberAnand_Mpec28-Dec-14 20:13 
GeneralRe: My vote of 3 Pin
maq_rohit a.k.a asthanarht5-May-15 14:55
professionalmaq_rohit a.k.a asthanarht5-May-15 14:55 
GeneralMy vote of 1 Pin
Dnyaneshwar@Pune22-Dec-14 23:43
memberDnyaneshwar@Pune22-Dec-14 23:43 
GeneralRe: My vote of 1 Pin
maq_rohit a.k.a asthanarht31-Dec-14 12:03
professionalmaq_rohit a.k.a asthanarht31-Dec-14 12:03 
GeneralMy vote of 1 Pin
waliullah.wa8-Dec-14 0:01
memberwaliullah.wa8-Dec-14 0:01 
GeneralRe: My vote of 1 Pin
maq_rohit a.k.a asthanarht31-Dec-14 12:03
professionalmaq_rohit a.k.a asthanarht31-Dec-14 12:03 
QuestionService got down - http://j.maxmind.com/app/geoip.js Pin
Uday Gaikwad18-Nov-14 22:42
memberUday Gaikwad18-Nov-14 22:42 
AnswerRe: Service got down - http://j.maxmind.com/app/geoip.js Pin
maq_rohit a.k.a asthanarht19-Nov-14 8:09
professionalmaq_rohit a.k.a asthanarht19-Nov-14 8:09 
GeneralRe: Service got down - http://j.maxmind.com/app/geoip.js Pin
Uday Gaikwad19-Nov-14 23:14
memberUday Gaikwad19-Nov-14 23:14 
QuestionGreat Pin
AnandMeena10-Aug-13 0:56
memberAnandMeena10-Aug-13 0:56 
AnswerRe: Great Pin
maq_rohit21-Aug-13 13:58
membermaq_rohit21-Aug-13 13:58 
Suggestionnot good Pin
Member 984651419-Feb-13 21:00
memberMember 984651419-Feb-13 21:00 
GeneralRe: not good Pin
albert arul prakash15-Apr-13 21:46
memberalbert arul prakash15-Apr-13 21:46 
Questioncomment Pin
Member 984651419-Feb-13 0:59
memberMember 984651419-Feb-13 0:59 
GeneralMy vote of 5 Pin
Member 984651419-Feb-13 0:58
memberMember 984651419-Feb-13 0:58 
QuestionUnbelievable Pin
Biswajit Giri4-Sep-12 6:08
memberBiswajit Giri4-Sep-12 6:08 
GeneralMy vote of 5 Pin
jrickegard17-Aug-12 2:02
memberjrickegard17-Aug-12 2:02 
GeneralRe: My vote of 5 Pin
maq_rohit17-Aug-12 20:52
membermaq_rohit17-Aug-12 20:52 
GeneralMy vote of 5 Pin
tanweer akhtar1-Jul-12 21:07
membertanweer akhtar1-Jul-12 21:07 
GeneralRe: My vote of 5 Pin
maq_rohit17-Aug-12 20:53
membermaq_rohit17-Aug-12 20:53 
Questionhttp://j.maxmind.com/app/geoip.js Pin
idlez29-Mar-12 17:02
memberidlez29-Mar-12 17:02 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 6 May 2011
Article Copyright 2011 by maq_rohit
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid