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
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="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 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

 
QuestionGreat PinmemberAnandMeena9-Aug-13 23:56 
AnswerRe: Great Pinmembermaq_rohit21-Aug-13 12:58 
Suggestionnot good PinmemberMember 984651419-Feb-13 20:00 
GeneralRe: not good Pinmemberalbert arul prakash15-Apr-13 20:46 
Questioncomment PinmemberMember 984651418-Feb-13 23:59 
GeneralMy vote of 5 PinmemberMember 984651418-Feb-13 23:58 
QuestionUnbelievable PinmemberBiswajit Giri4-Sep-12 5:08 
GeneralMy vote of 5 Pinmemberjrickegard17-Aug-12 1:02 
GeneralRe: My vote of 5 Pinmembermaq_rohit17-Aug-12 19:52 
GeneralMy vote of 5 Pinmembertanweer akhtar1-Jul-12 20:07 
GeneralRe: My vote of 5 Pinmembermaq_rohit17-Aug-12 19:53 
Questionhttp://j.maxmind.com/app/geoip.js Pinmemberidlez29-Mar-12 16:02 
GeneralNot working in my local host ,couuld you please explain me h... Pinmembersushant58728-Dec-11 19:58 
GeneralNot workin on my local host. Pinmemberkeyur soni2-Jun-11 2:02 
Generalthanks PinmemberMember 473572011-May-11 21:10 
GeneralThanks Pinmembermaq_rohit7-May-11 6:27 
GeneralNice... PinmemberGPUToaster6-May-11 18:53 
GeneralDoes not work well in South Africa PinmemberSchalk en Adele8-May-11 20:37 
GeneralAwesome! PinmemberRaghu Karupakala6-May-11 7:50 
GeneralRe: Awesome! Pinmembermaq_rohit7-May-11 6: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 | Mobile
Web02 | 2.8.140821.2 | Last Updated 6 May 2011
Article Copyright 2011 by maq_rohit a.k.a asthanarht
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid