The User Location API uses the IP address of the visiting user to attempt to locate them to the closest city found in the weather providers database.
Because there are over 4 million IPs and they are continually being reassigned to different places, the IP lookup service is not 100% accurate and never will be.
If a suitable IP location is not located it will fall back to your default location. My plugin uses ipinfo.io to locate the user. You can visit that page to see where the service thinks you are.
Users are able to use HTML5 Geolocation which is based off latitude and longitude and more accurate. Note: some browsers only support HTML5 Geolocation on websites that use HTTPS.
The example widget on the demos page is using this functionality. Please test this widget to determine if my plugin will work in your location and for your needs.
Sequence of ‘Use User Location’
The plugin goes through a few checks once activated:
- On the first visit of your user, the plugin will attempt to use the IP address to find the city.
- If a city cannot be found it will prompt the user to set their own city:
The reason this workflow was developed is designed around the user experience.
Getting the city based off the IP is a good first attempt because the user doesn’t have to do anything (and is generally pretty close).
The HTML5 Geolocation method opens a popup and asks the user for ‘Access to their location’ when they first hit your site. This may be confusing to the user, especially if your weather widget is not immediately visible on the page (in the footer).
You can always build a custom template with a different workflow.
To turn on the user location features, you can do so in the widget settings by clicking the ‘Use User Location’ checkbox.
You can also pass an attribute when using a shortcode to setup your widget:
Starting in version 1.1 there are two new options that should appear when you check the checkbox in the widget settings. You can now select to auto grab the C or F and also allow the user to change their weather.
If you choose the ‘Allow User to Change the Location’ setting, (attribute
allow_user_to_change="1" in the shortcode) your widget should show a small map marker in the corner of your widget.
When clicked it will prompt the user to allow your website access to their location.
If the user allows the request, your widget will populate (via AJAX, no page reload) with the new city data. If the user blocks the request they will be presented with a search box to choose their own city.