Click here to Skip to main content
Click here to Skip to main content

Tagged as

How to find current location based on the IP-address using JavaScript

, 6 May 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Sometimes we have to get the current location info, e.g., country code, country name, etc. using the latitude and longitude. Though there are lot of ways to accomplish this task, I found a very easy way to do this. And definitely its worth sharing as a tip and trick.
The following JavaScript code is used to find the location, latitude, and longitude based on your IP address:
<script language="JavaScript" src=""></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>
<script language="JavaScript">document.write(geoip_city());</script>
<script language="JavaScript">document.write(geoip_region());</script>
<br>Region Name:
<script language="JavaScript">document.write(geoip_region_name());</script>
<script language="JavaScript">document.write(geoip_latitude());</script>
<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.


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


About the Author

maq_rohit a.k.a asthanarht
Technical Lead
United States United States
Rohit is a Lead Engineer from NCR. He 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
Follow on   Twitter

Comments and Discussions

GeneralMy vote of 1 PinmemberDnyaneshwar@Pune22-Dec-14 23:43 
GeneralMy vote of 1 Pinmemberwaliullah.wa8-Dec-14 0:01 
QuestionService got down - PinmemberUday Gaikwad18-Nov-14 22:42 
AnswerRe: Service got down - Pinprofessionalmaq_rohit a.k.a asthanarht19-Nov-14 8:09 
GeneralRe: Service got down - PinmemberUday Gaikwad19-Nov-14 23:14 
QuestionGreat PinmemberAnandMeena10-Aug-13 0:56 
AnswerRe: Great Pinmembermaq_rohit21-Aug-13 13:58 
Suggestionnot good PinmemberMember 984651419-Feb-13 21:00 
GeneralRe: not good Pinmemberalbert arul prakash15-Apr-13 21:46 
Questioncomment PinmemberMember 984651419-Feb-13 0:59 
GeneralMy vote of 5 PinmemberMember 984651419-Feb-13 0:58 
QuestionUnbelievable PinmemberBiswajit Giri4-Sep-12 6:08 
GeneralMy vote of 5 Pinmemberjrickegard17-Aug-12 2:02 
GeneralRe: My vote of 5 Pinmembermaq_rohit17-Aug-12 20:52 
GeneralMy vote of 5 Pinmembertanweer akhtar1-Jul-12 21:07 
GeneralRe: My vote of 5 Pinmembermaq_rohit17-Aug-12 20:53 
Question Pinmemberidlez29-Mar-12 17:02 
GeneralNot working in my local host ,couuld you please explain me h... Pinmembersushant58728-Dec-11 20:58 
GeneralNot workin on my local host. Pinmemberkeyur soni2-Jun-11 3:02 
Generalthanks PinmemberMember 473572011-May-11 22:10 
GeneralThanks Pinmembermaq_rohit7-May-11 7:27 
GeneralNice... PinmemberGPUToaster6-May-11 19:53 
GeneralDoes not work well in South Africa PinmemberSchalk en Adele8-May-11 21:37 
GeneralAwesome! PinmemberRaghu Karupakala6-May-11 8:50 
GeneralRe: Awesome! Pinmembermaq_rohit7-May-11 7:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    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
Web01 | 2.8.141223.1 | Last Updated 6 May 2011
Article Copyright 2011 by maq_rohit a.k.a asthanarht
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid