MJ
asked on
Detect User's State Using JavaScript (Not using Geo-location)
Is there an easy way to find out a user's state (e.g. CA.) using JavaScript? I don't want them to have to opt-in like GEO-location. I've seen a few IP look-up options but trying to find the easiest way.
Thanks!
So, here a code : https://leak.im/29219001/
I got Florida and, yes, this is a closest state from my country, wonderful :)
I got Pennsylvania yet I am in Southern Ontario, closest state is New York
I got Florida and, yes, this is a closest state from my country, wonderful :)
I got Pennsylvania yet I am in Southern Ontario, closest state is New York
I know it's not perfect as the file use average lat/lng for each state
...but, I see Pennylvania near South Ontario on my map
...and yes you know where you're living more than me @David :))
If we found a file with points delimiting states, we probably can do better than using average points... of course !
...but, I see Pennylvania near South Ontario on my map
...and yes you know where you're living more than me @David :))
If we found a file with points delimiting states, we probably can do better than using average points... of course !
@leakim "I don't want them to have to opt-in like GEO-location"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
No, I don't want to have to have the user opt-in.
Thanks!
No, I don't want to have to have the user opt-in.
Thanks!
so it's game over, you can't access user WAN IP address from a browser until you're ok to use an external web service, maybe your own and why do you need a JavaScript solution when this info is available on server side.
using CGI : https://www.oreilly.com/openbook/cgi/ch02_02.html
using CGI : https://www.oreilly.com/openbook/cgi/ch02_02.html
os.environ["REMOTE_ADDR"]
=> https://w3c.github.io/geolocation-api/#navi-geo
=> https://developer.mozilla.org/fr/docs/Web/API/Geolocation/getCurrentPosition
now, you need to find a database which have delimiters of each state, did not find one yet(?) but you've this one :
https://gist.github.com/meiqimichelle/7727723
So, here a code : https://leak.im/29219001/
I got Florida and, yes, this is a closest state from my country, wonderful :)
Open in new window