# Problem with GMT offset.

• May 9th, 2011, 06:39 AM
sush
Problem with GMT offset.
I want to write a program that takes input as latitude and longitude of a particular place and gives output as that place country GMT offset. I have done gmt=longitude/15. example: (Chicago) latitude=41.85N, longitude =-87.65W , GMT= -87.65/15 =>-5.8 but chigago actual GMT is GMT-5(this is country based). so how can i decide that which range of lat and longs comes under which country?and how to get Actual GMT. Its not the rounding problem, if i round that to -6 ,then that is GMT offet for other country.. is there any java api's to find location, based on lat longs?? please help me.
• May 9th, 2011, 01:18 PM
KevinWorkman
Re: Problem with GMT offset.
Do you know how you would do this without a program? As in, if you had to do this using only a piece of paper and a pencil (and whatever other resource), would you know how?

If so, write out what you would do, and you'll have a pretty close approximation to an algorithm.

If not, google is your friend. I don't really understand what the problem is, so perhaps writing out your problem a little more clearly would help also.
• May 10th, 2011, 01:32 AM
sush
Re: Problem with GMT offset.
OK ..The thing is i need java code to find GMT offset for a given latitude and longitude. But Gmt should be country based in which the given city exists. f

For ex:

If i give lat longs for Mumbai(city), i should get India GMT(country) not the mumbai gmt,because mumbai is in India. Reason is except some countries each country has only one GMT .
• May 10th, 2011, 08:37 AM
KevinWorkman
Re: Problem with GMT offset.
The short answer to your question is: no, there isn't an easy way to do this.

You're going to need to rely on a webservice that gives you the timezone for a given city, or a data structure that does the same, possibly from a third party library.