jQuery offers a great way to find out where your website visitors geographic location. With a simple jQuery GeoLocation API call you find out your website viewers Country, Region & City. You can also find out thier Longitude and Latitude values to hook upto Google Maps to show where they are viewing from. The great news is that this service is completely free! :)

I’ve included an alert box to help you get it working, you should see something like this:


How to use jQuery GeoLocation:

  1. Copy the jQuery code below into the section of your webpage
  2. Copy the HTML code below into the section of your webpage
  3. Watch it’s magic!

jQuery Code:

HTML Code:


It could be useful for registration forms which require the user to fill in thier location details, this is a form that I have auto populate form select dropdowns using jQuery GeoLocation method above:


You can view a live demo of this on signup form.

GeoLocation API Details

GeoPlugin offers the following features:

  • Geo Location services
  • Location Statistics
  • Currency Converter
  • Location codes, symbols & abbreviations
  • Latitude/Longitude to place or post code

Geo Location services are available in the following formats and programming languages:

  • Javascript
  • PHP
  • JSON
  • XML
  • ASP

Full details can be found here: http://www.geoplugin.com/webservices/javascript

Tags: jquery geolocation, jquery geoplugin, jquery get users city, jquery get users country, jquery get users region, jquery location api, jquery Longitude Latitude
Sam Deering is a Front-end Web Developer who specialises in JavaScript & jQuery. Sam is driven and passionate about sharing his knowledge to educate others.

Free Guide:

How to Choose the Right Charting Library for Your Application

How do you make sure that the charting library you choose has everything you need? Sign up to receive this detailed guide from FusionCharts, which explores all the factors you need to consider before making the decision.

  • Pingback: Get GeoLocation using jQuery (API) GeoPlugin | PHPmyscript()

  • http://www.flirtbox.com Toby

    I can not see this in the demo!

    • jquery4u

      @Toby – I am still working on the new version of this website. The demo should be up soon! Thanks for your patience!

  • Pingback: Get Geo Location with 2 lines of JavaScript | jQuery4u()

  • Harry Saggu

    Through this site i came to know how to use jQuery Geological application .but by making some changes in jQuery we have make an Geological application which gives location, date as well as temperature of current location.


  • Your Fnf

    hey guys, u need to include the following line before the scripts

    <script src="http://www.geoplugin.net/javascript.gp&quot; type="text/javascript"

    Only then it will work

  • darkkean_acn

    For everyone, here’s a fiddle for a quick demo: http://jsfiddle.net/darkkean_acn/9cr55/

  • johnny

    i get only country name but not city name

  • Safa

    Thanks a lot ! Worked like a charm and worked as i wanted for a project of mine :) Many thanks for sharing ♥

  • http://anishmalias.url.ph/ Anish M Alias

    how to convert currency ? is it possible

  • http://anishmalias.url.ph/ Anish M Alias

    i want this.. my webpage added price list. if the site open in USA the prices shows in doller.. in which country the site logged, the price will be automatically converted to native currency. pls help me. if it is possible..

  • moosa

    Can someone please help me out, i did as it says but the boxes comes empty

  • http://www.facebook.com/sudhir600 Sudhir Gupta

    where is the demo.. its not working for me..

Special Offer
Free course!

Git into it! Bonus course Introduction to Git is yours when you take up a free 14 day SitePoint Premium trial.