Posted on 22 Comments

WordPress Accurate Geolocation

Many of businesses which run operations close to a particular market need nowadays to understand from which locations their visitors, users or customers are accessing their website, from where they are using the website, from where they are placing orders or booking services.

There are for sure usage scenarios of high accurate geolocation data for such business owners and just to name a few, consider these ones:

  • a local news website which wants to advertise stores in close proximity of it’s visitors or users
  • a restaurant which takes online orders with pick-up delivery
  • a barber shop, hairdresser saloon, medical shop which wants to expand and needs to position the next locations in proximity to it’s existing customers
  • etc.

We have the technology

Believe it or not, the technology is there. It’s called mostly HTML Geolocation and has been introduced with HTML5 standards. The information is more accurate if they are provided from smart devices, such as mobile smart phones or Apple Mac’s, since these are using with WiFi or GPS positioning, etc. but also in older or simpler devices the accurate geolocation can be provided.

HTML Geolocation Browsers
HTML Geolocation Browsers

The W3C standard specifies that the user must be prompted and asked for before getting geolocation information. Most or all modern browsers implement HTML5 geolocation. Learn from which versions they do so following this link

One important thing to remember is that W3C is slightly implemented differently by browsers. For example, Chrome would ask for your permission to set location data and would store this information permanently, so that next time you will not be asked (unless you clear-out your settings); Safari asks you each time the geoPosition.getCurrentPosition method is being called and you just have an option to remember your answer for 24 hours; and so on.

You can follow this link for more information W3C API specifications at

WordPress Accurate Geolocation plugin

Before WordPress Accurate Geolocation plugin, there was no easy way to ask visitors about their geolocation. We’ve introduced this free plugin in WordPress Plugin Directory, free and open source!

WordPress Accurate Geolocation gets accurate geolocation based on GPS, WiFi and other modern techniques to identify latitude, longitude, altitude, accuracy, speed, heading of visitor and if logged in, user id.

Getting the data

The triggers of getting the information are on page/window load and/or through the click of a button, link, etc. These are configurable setting options.

For configuring the button, the button just needs to the id of value aglId, as follows:

Test it out!

Storing the geolocation information

The information can be stored in cookie and/or database, in wp_options and/or wp_usermeta tables. These are configurable setting options.

The information accessed directly from the cookie, or from WordPress ajax, or from the databse.
To do so

  • from cookie, look for the cookie named agl-value; data is encoded into JSON format
  • from cookie, using WordPress AJAX with action agl_ask
  • from WordPress database, wp_options table; note, to delete the data from wp_options, you can tweak the code below, replacing “SELECT *” with “DELETE” or simply by clicking the Delete button on the plugin options page
  • from WordPress database, wp_usermeta table

Other plugin settings available:

  • cookie expiration time
  • format mask of timestamp retrieved and stored
  • HTML Geolocation high accuracy option, according to W3C specification
  • HTML Geolocation maximum age option, according to W3C specification
  • HTML Geolocation timeout option, according to W3C specification

Download from

Access this link to install WordPress Accurate Geolocation,

Interested in seeing your visitors and users on a map?

WordPress Accurate Geolocation Map plugin lets you plot our visitors and users on Google Maps to see exactly from where they are accessing your website. This extension is offered by WooReports team, for more information go to and learn how easy it is to set it up and use it.

Lucian Capdefier

Analytics Evangelist / WooReports Author at WooReports
I have more than twelve years of experience in successful business and technical consulting, system design, development, implementation, training and support of mission critical systems, leveraging data integration, data management, analytics and information optimization to provide business advantage.

Latest posts by Lucian Capdefier (see all)

Share now and help us in making WooReports popular
Share on Facebook
Tweet about this on Twitter
Share on LinkedIn
Posted on 22 Comments

22 thoughts on “WordPress Accurate Geolocation

  1. hi Lucian,

    if I install this nice plugin, how can I use the informations it generates
    in a dinamical php page of wordpress?
    I would need in particular lat and lon




    1. You can use it from the cookie, db.

      What do you want to achieve?

  2. I would like to be able to load a specific wordpress post based on the users location. When they are near the location, if they have the site open, I want it to make a noise and show a page specific to that location

    1. Hi Thomas,

      The logical steps would be:
      – define a list of your lat/long locations next to which you will show the page/post – let’s call this locations A
      – catch the users location – call this location B; see here how
      – compute the distance between each of the locations A and location B, example on how to calculate distances between two points while having lat/long information here
      – if the user is within a range (e.g. less than 100km or whatever) then do the redirect to the page/post; maybe using wp_redirect, like described here; you can google for raising sound effects or whatever else you need

      Hope this helps!

  3. I installed the plugin, Are the settings are at default I went to the home page, it asked me for permissing to get GPS data, I clicked yes. I’ve looked in the $_COOKIE array and the wp_options table, but I don’t see any GPS data. Is there something else I have to do?

    1. Hi Peter, you need to look in the cookie called agl-value, in your browser. In wp_options, you need to look for key option_name LIKE ‘agl_data_%_%’.

      We hope this article clears everything out for you. In case it does not, please comment back.

    2. Course, your browser should be sending data. The browser implements GPS in different ways, so please try to run some tests in Safari on iOS, Safari on Apple Macs or anything else on Windows to see what results you get. Some are pin-point, within 1-2 meters in accuracy, some indicate just the city center, if, for example, you are in a city.

  4. Hi there,
    it works only if the user is an administrator. If it is a simple subscriber, it reads “No data available” in a pop up box.
    And then in the inspector / debug console, it reads : TypeError: aglPhpParams is undefined
    What to do ? I can’t put all my users as Administrators…

    1. Dear Seb,

      Please see the below the link to screenshots which were captured on non-admin users.


  5. Hello, Thanks for this awesome plugin. I would love some help from you about something. I am creating a contact us form in my site and would like to include geolocation of the sender with the form.
    For example, along with Name, Email, the user could click a button to send their lats and longs in the email sent by the WP site to us. How would I accomplish this?
    Thank You.

    1. Thanks for the feedback!

      See article here:

      1. Set the right config
      2. Use algId for a html button tag as id


  6. I’d like to use this plugin on my site but am unclear how to call the function directly. I’d like to load the geoloc info automatically when the user accesses a page but only that one page. I can’t use the button as I don’t want to wait for the user to find that and click it. I also can’t use the autoload on page option as that appears to trigger it on every page on my site. I suspect that many users will ignore or decline it when hitting my home page. If they’re not sure if they’re going to stay on my site I’d rather not scare them away by asking for geoloc info.

    What I’d really like to do is just call the function directly but only when I hit the page where geoloc info is obviously useful and needed (mapping for instance). Is that possible? I’ve poked around the code but I don’t see anything obvious in the php and I guess my js skills are not strong enough as I haven’t been able to call that directly either.

    Any help or guidance with this would be greatly appreciated.


  7. A lot of thanks for the plugin. I´ve installed it and it works fine, but i can´t find the user id in the value in database. This is an example of the information in database: “a:13:{s:8:”latitude”;s:10:”41.3870436″;s:9:”longitude”;s:19:”-4.7094945999999993″;s:8:”altitude”;s:1:”0″;s:8:”accuracy”;s:2:”28″;s:16:”altitudeAccuracy”;s:1:”0″;s:7:”heading”;s:3:”NaN”;s:5:”speed”;s:3:”NaN”;s:10:”error_code”;s:0:””;s:13:”error_message”;s:0:””;s:8:”php_time”;i:1468223886;s:8:”php_date”;s:19:”2016-07-11 09:58:06″;s:15:”php_date_format”;s:11:”Y-m-d H:i:s”;s:7:”user_id”;i:0;}”
    Where is the information about the user id? Thanks.

    1. In the array you’ve pasted see last variable – user_id. If the value is zero, as you’ve pasted it, then the user is not logged in; if the value is grater then zero, then that’s the user id of the website visitor.

      Hope this helps,

      1. Lot of thanks. This array is from a logged in user. I´ve seen other logged in user arrays and always is zero. Maybe I must modify any option? When a user logs in, appears an alert “No data available!”, maybe this is signifcant for you.


  8. A lot of thanks for this plugin. A question: if the connected user has the gps on in his mobile phone, then the lat and long data will be exact, isn´t this way? A lot of thanks.

  9. I have installed the plugin and it´s one of the more advanced for wordpress geolocation at this moment. Thanks¡

  10. Is there a way to change the table that this data is saved to instead of wp_options? I would like store them in a dedicated table to keep things clean.

    1. Hi Thomas,

      Not unless you modify the source code. There is no feature developed that does that.

      But data is partitioned in wp_options by type. So I see no chanse to become unclear…


  11. Is there a way to insert into a different table instead of wp_options?

  12. Hi, this is random, but where did you get the html template for this website? Thank you!

    1. Please see footer notes.

Leave a Reply

Your email address will not be published. Required fields are marked *