These days it is quite common to see websites asking permission to access user locations. There are multiple use-cases of using location data to personalise your web content and deliver targeted messaging.
This feature can be enabled in any website by using HTML 5 Geolocation API and is widely supported by all current web browsers including Chrome, Safari, Firefox, IE and Opera.
The main function which triggers the browser to prompt a user to share his/her location is:
This will return a simple latitude and longitude coordinates of the user. In most instances, this coordinate is not particularly useful until it is converted into detailed locality information.
This is where a Reverse Geocoding API comes into play. There are various APIs available in the market for converting your geo-coordinate into readable location information. You can read more about it in our previous blog post here and learn about BigDataCloud’s Reverse Geocoding API.
BigDataCloud's Reverse Geocoding API is the first to deliver administrative/non-administrative boundaries-based results and as such, it is the perfect choice when you need to resolve a user's practical area such as their city, state or country rather than their street address.
The API provides:
- Detailed locality information of a user
- Postal code level accuracy for the U.S, Great Britain, and Australia.
- Exceptionally fast response time (sub-millisecond)
- Supports 147 common world languages.
- Unlimited FREE Client-Side Reverse Geocoding to City API
- Affordable Server-Side Reverse Geocoding API
For any developers who need real-time and accurate user location, BigDataCloud is the perfect solution.
Using BigDataCloud’s Free Reverse Geocoding API
BigDataCloud has 2 types of Reverse Geocoding API :
- FREE Client-Side Reverse Geocoding to City API
- Reverse Geocoding to City API (Free up to 50,000 queries per month)
FREE Client-Side Reverse Geocoding to City API
The API is straight forward. Simply pass the latitude and longitude retrieved by the getCurrentPosition function and you will receive a JSON output contained detailed locality information.
The output of the API in JSON format.
Code Pen Example
Please click here to test the demo.
Best practises of using the FREE Client-side API
The Reverse Geocoding API is free to use for client-side implementations only. If you wish to implement the API in a server-side application or scenario then you will need to use the server-side API version which comes with a FREE allowance of 50,000 requests per month.
The client-side API is restricted to client-side implementations only and if you are found abusing the API then your account will be banned.
Client-side implementation means that the API should be called in real-time when the user provides their geo-coordinates via browsers, mobile apps or desktop apps. Any operations on stored geo-coordinate values from database, file or internal variables, which are not originating from the user’s action(client-side), will be considered a server-side implementation.
A server-side example would be to capture the latitude and longitude from the browser and to submit this coordinate to the server for processing. A regular use-case for this scenario is to geo-tag content submissions such as photos or videos which can then be further identified and processed using a Reverse Geocoding API, often in batch execution. In this instance, the server would be performing the API request at a separate time and from a separate location. Requests of this type are not permitted on the Free Client-side API and must be made using the Server-side API.