What’s the most efficient way to get a United States user’s State? Is HTML5 Geolocation an option without needing to involve google maps?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Here’s a couple of examples in JavaScript and JSON (with the help of jQuery) using both the IP lookup method (with the help of IPinfoDB) and the Geolocation API method (with the help of Google Maps API and YQL).
In both examples I’m retrieving the region and country but there are several values you can choose from. Be aware these examples don’t do any error handling and here they are edited for brevity, otherwise see the full demo.
IP Lookup in JavaScript
This method is good because it’s easy to implement and is fairly accurate at a country level but accuracy drops considerably for anything more specific.
Geolocation API
Although by no means perfect, this method is as accurate as it gets. User is prompted to share geolocation details which may reduce usage.
In there you’ll see I used the Google Maps API v3 by way of YQL so that a JSON callback is possible.
Full demo: http://jsfiddle.net/ZjXXh