I want to get clients Time Zone offset from his IP address for my web app. I have tried using Javascripts getTimezone function, but, some clients have their timezone or time set incorrectly. I want to get the offset and render some information back on client based on their timezone.
Thanks for taking time to read the question. I am open for alternate approaches too.
Regards,
Vamyip
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
If you can call a web service, you might like to try ipinfodb.com. For example:
http://ipinfodb.com/ip_query.php?ip=69.59.196.211&timezone=true
returns:
<Response> <Ip>69.59.196.211</Ip> <Status>OK</Status> <CountryCode>US</CountryCode> <CountryName>United States</CountryName> <RegionCode>41</RegionCode> <RegionName>Oregon</RegionName> <City>Corvallis</City> <ZipPostalCode>97333</ZipPostalCode> <Latitude>44.4698</Latitude> <Longitude>-123.343</Longitude> <TimezoneName>America/Los_Angeles</TimezoneName> <Gmtoffset>-25200</Gmtoffset> <Isdst>1</Isdst> </Response>
A faster option is to use the free MaxMind Geolite city. If it is not good enough, you can apparently upgrade to a more accurate paid-version. I can’t speak for the quality of the paid version, as I have never used it. You can download the file binary blob version of the same database, and then use the C# class to query it.
Method 2
google ‘geolocation ip’
There are API’s you can call provided by companies. Some are free, some are not.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0