Is there a way to find a clients location on a website using just jQuery. For example, if a user comes to my site, how could I find out what their approximate location is just using jQuery. For example, if a user came from San Francisco CA it would have some type identifier to let me know the user came from San Francisco CA. I wouldn't really need their exact location just the county or general area of origin.
edit: How is the information on http://flourishworks-webutils.appspot.com/req generated?
Thanks
You can use a web service that supports JSONP, such as my service http://ipinfo.io. It'll provide you with the client's IP address, hostname, geolocation information and network owner. Here's an example of it in action with jQuery:
Here's a more detailed JSFiddle example that also prints out the full response information, so you can see all of the available details: http://jsfiddle.net/zK5FN/2/
The HTML5 Geolocation API allows you to get a user's Latitude/Longitude with some JavaScript (if the browser is compatible, and if the user allows access to his/her location).
You can then reverse-geocode the location to get an address, there are several free reverse-geocoding services other than Google's API.
However, if you don't need accurate location, and if you want all your users to take advantage of the feature (no matter the browser), and if you don't want to ask them whether they allow your site to have their location, I would recommend to use your user's IP to get the location.
This is possible with https://ip-api.io geo location API. It provides country, city, zip code, coordinates, network, ASN, timezone. For example with jQuery:
Also https://ip-api.io checks TOR, public proxy and spammer databases and provides this information as well.
Example response:
I created the ipdata.co API to provide a solid solution to this, see the below fiddle to play with. It returns numerous useful datapoints, such as - location: country (name and code), region, city etc., ecommerce - currency_code, currency symbol, timezone, mobile carrier data and it detects whether the IP address is a Proxy or a Tor user.
Ipdata has 10 global endpoints each able to handle >10,000 requests per second.
See the fiddle at https://jsfiddle.net/ipdata/6wtf0q4g/922/
To get the client IP address & country name in jQuery: