Geolocation API Demo: Local Weather
Nearly all modern browsers support geolocation. This way web applications are able to work with the user’s location. As an example application I made a small website, that shows the name of the city you are in right now, and current weather conditions.
→ Demo Page ←
And this is how it works:
- The Weather Data is from the inofficial Google Weather API. First, the API is called using coordinates. This does not always work well, in this case the API is called using the retrieved city name.
The API call finds place in a PHP script using cURL – this script then is read using AJAX.
- The error message „Couldn’t find your location.“ mostly occurs, when the geolocation permission request is answered too late. Reload the site and give the permission faster.
- There is a bug in Safari, which occurs when the Geolocation API is called repeatedly. Restart Safari.
- Internet Explorer is not supported. Geolocation API works best with Chrome.
- Currently, temperature is always shown in Celsius, because it is used world wide and not only in the US like Fahrenheit.