3

I am working on an iPhone application in which i want to find the latitude, longitude and timezone details of any place.

How can i get all these details at a time.

we can find the latitude and longitude easily but how can we get the exact time zone of that place?

Could any one please guide me ?

Thanks.

Mayur Prajapati
  • 5,454
  • 7
  • 41
  • 70
Nithin S
  • 109
  • 1
  • 7

7 Answers7

3

It looks like you want this:-

NSString *timeZoneName = [[NSTimeZone localTimeZone] name];

That returns "Asia/Kolkata" for me.

if you are using systemTimeZone then it represents the timezone used by the system (device) itself. The localTimeZone returns an object that represents the current default time zone for the application.

use this API for getting the data and pass lat and long values.

Api for getting timeZone

Balu
  • 8,470
  • 2
  • 24
  • 41
  • yeah but i want to find name of any timezone in the world. How can i get that? – Nithin S May 13 '13 at 07:33
  • @Nithin S:Have you got the answer? – Balu May 13 '13 at 08:09
  • @NithinS this is the correct answer but not that explicitly explained. What sunny means is that you should first get the lat and lon of the target place, and then send a call to that google api website which will return the time zone (as in the link given on the example). Forgot to mention. Some google services have a limitation in the number of calls you can make to them and the purpose of the calls. Be sure to read the details of this specific api. – Pochi May 13 '13 at 10:17
  • Hey sorry. I understood what you guys said. Thank you so much for the suggestions. I have already tried that few days ago but the problem is that for some latitude and longitude values webservice does not give the proper time zone values. So i am not so willing to use webservice. Is there any other alternative? – Nithin S May 13 '13 at 11:03
  • @NithinS no, getting the time zone is based on the location and it varies from country to country (daylight saving for example). So you need to call a database that knows this. Still why do you say it doesnt work? google api should return various parameters which you can use to calculate whatever you want. – Pochi May 14 '13 at 04:23
1

You can get Longitude and Latitude using CoreLocation.

add this in your .h class where you want the latitude and longitude.

#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>

@interface CoreLocationViewController : UIViewController <CLLocationManagerDelegate> {
    CLLocationManager *locationManager;
}
@property (retain, nonatomic) CLLocationManager *locationManager;
@end

And in your .m file

#import "CoreLocationViewController.h"

@implementation CoreLocationViewController
@synthesize locationManager; 

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    [self setLocationManager:[[CLLocationManager alloc] init]];
    [locationManager setDelegate:self];
    [locationManager setDistanceFilter:kCLDistanceFilterNone]; 
    [locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
    [locationManager startUpdatingLocation];
}

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {

 NSLog(@"My Latitude %f",newLocation.coordinate.latitude);
 NSLog(@"My Latitude %f",newLocation.coordinate.longitude);

}

And for the current TimeZone you can use

NSTimeZone* currentTimeZone = [NSTimeZone systemTimeZone];
NSDateFormatter *dateFormatter = [dateFormat setTimeZone:currentTimeZone];
NSDate *rightNow = [NSDate date];
NSString *dateString = [dateFormatter  stringFromDate:rightNow];
Ahmed Z.
  • 2,329
  • 23
  • 52
  • Z: i want to fine the time zone of any place in the world instead of current time zone. or atleast the timezone name of any place in the world. is there any way to find that? – Nithin S May 13 '13 at 07:30
  • dude When your app will be running lets say London, England then it will give the timezone of that particular place. – Ahmed Z. May 13 '13 at 07:35
  • Or is that you want to make something like a timezone finder thing that they have in world clocks? like this one http://www.timeanddate.com/time/map/ – Ahmed Z. May 13 '13 at 07:36
  • dude i understood what you are saying. you are talking about current or local time time. what i want is time zone of any place. lets say i am in india and i want to find the time zone of London or any other place.hope you are clear about my question now. – Nithin S May 13 '13 at 09:10
  • right so you want something like this http://www.timeanddate.com/time/map/ in your app...? – Ahmed Z. May 13 '13 at 09:40
1

Get NSTimeZone from CLLocation: https://github.com/Alterplay/APTimeZones This utility works locally on device with no 3d party service.

slatvick
  • 1,207
  • 2
  • 16
  • 25
0

You can get time zone from any device by using

NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];

Deepesh Gairola
  • 1,252
  • 12
  • 18
0

you are get location from CLLocationManager and you are also take a look at Geonames.org

It's a free webservice that allow you to get a lot of informations from a long/lat

They also provide a free (and open source) Java Client for GeoNames Webservices library (library for other language also provided: ruby, python, perl, lisp...)

Here's some info you can get from long/lat: (complete list of webservices here)

Find nearest Address

Find nearest Intersection

Find nearby Streets

Elevation Timezone

Sumit Mundra
  • 3,891
  • 16
  • 29
0

If you want to know using api in that case you can get using this api but in this api first you find your latitude and longitude using CLLocationManager class and then put in this api.

http://ws.geonames.org/timezone?lat=#{lat}&lng=#{lng}

And read google doc for more api.....

https://developers.google.com/maps/documentation/timezone/

i Hope it may help you

Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
0

iOS 5 added the CLGeocoder class which can do the lookups you want. It operates asynchronously (I presume it's querying a server somewhere) but you give it a location and it gives you a great deal of information back, including the time zone. The question was asked for Objective C but I'm going to answer using Swift. The Objective C version should be easy to derive since the APIs are the same.

This is a Swift Playground snippet looking up a location in the UK:

import CoreLocation

let location = CLLocation(latitude: 51, longitude: -0.1)
let geocoder = CLGeocoder()
geocoder.reverseGeocodeLocation(location) { (placemarks, error) in
    if let error = error {
        print(error.localizedDescription)
        return
    }
    
    if let placemarks = placemarks {
        for placemark in placemarks {
            print(placemark.name ?? "no name")
            print(placemark.locality ?? "no city")
            print(placemark.administrativeArea ?? "no state/province")
            print(placemark.country ?? "no country")
            print(placemark.timeZone?.abbreviation() ?? "no time zone")
        }
    }
}

And this is the output:

1234 A Street Address
Haywards Heath
England
United Kingdom
GMT+1

I intentionally changed the address line in the output above so that spambots don't scrape it and start soliciting the poor soul whose coordinates I arbitrarily chose.

John Stephen
  • 7,625
  • 2
  • 31
  • 45