I know there're a lot services to give timezone given latitude and longitude. But is there a way to get the timezone for a device without providing location information?
Related
Please Give me some solution to get accurate location even inside the building.
Is there any way to get location of the iPhone without demanding location services from the user? It should not be really accurate.
edit: I have no problem with implementation of location services. I try to find an alternative way
No this is not possible.
Apple has made location service abstract so you can't really see which technic is used. Thus if the user turns off the location service you can't get the location any other way.
There is however the option to check the user IP and get a very rough location.
The scenario is a iPhone user who doesn't want the time to automatically update when he travels abroad and thus has disabled the system setting "Set Automatically" for time zones, leading to [NSTimeZone systemTimeZone] not updating for his new location.
As a developer, can I still find out the current local time and time zone for the (possibly new) country the device is in?
No. Not without some work anyway, and maybe not with some work.
If the user has disabled auto time zone setting, the only time zone you get to know about is the one that they've told their phone to use. You don't get to bypass their preferences on that. Unfortunately you also don't get to find out if they've done that. All you get is a time zone, but why that's current is not something you can answer.
If you're determined, you might try using Core Location to get their latitude and longitude, and work out a time zone from that. Doing that reliably may be a challenge-- the official IANA time zone database includes lat/long, but only at one location within each time zone. There are services like AskGeo that claim to solve this problem (they might be fantastic, I haven't tried them). But that obviously requires a network connection, and people traveling to other countries are probably less likely than average to have mobile data access.
Is there a API available for converting Address to Timezone?
I have an idea of using Google GEOCODE API for converting Address to LAt long and then Timezone api to convert it into timezone.
Is this is a viable option? Has anyone done this in past?
Do we have any other options?
There's always askgeo.com. They do exactly what you are looking for.
Also, this question was previously answered here
SmartyStreets will return lat/long and time zone data for United States addresses, all in one step. You can do this via API or a list upload. Just keep in mind that time zone data can change, so you would need to update your data every once in a while to keep up with those changes (if you're planning on keeping some sort of database, etc.)
Another thing to be aware of is Daylight Savings Time observance, which SmartyStreets also indicates in its returned data. You can see a full list of our output fields here.
(Disclosure: I work at SmartyStreets)
Update - 11 Jan 2016: SmartyStreets now processes international addresses.
In iOS, I need to know the actual time (UTC), not the time of the device. In other words, it should not be possible for the user to tamper with the time or date.
Anything that requires a network connection is not good (so accessing a time server is not an option).
AFAIK, there are 2 theoretical ways of achieving this:
Use the timestamp from the GPS satellite signal
Get the current time from the carrier
Problem is that this information is not exposed by any API in iOS.
Is there another way?
Most solutions you could possibly find (including getting GPS data from CoreLocation to access the time information) are flawed because they are depending on the actual device to access time time. You will need to connect to a time server (i would suggest to check for NTP server). I was looking at the core telephony framework and couldn't find anything that would provide the network time. You might want to fill a bug report and request apple to expand one of the classes to include the time.
You could have a look at secondsFromGMTForDate: and secondsFromGMT in NSTimeZone. If the GMT offset increases/decreases when the time of the device is changed, these provide a way to correct your timestamps to GMT (and probably convert to UTC).
You can't get to the raw GPS data and the timestamp property of the CLLocation in locationManager:didUpdateLocations: is set with the system clock