2013-05-13 88 views
3

我正在研究一個iPhone應用程序,我想查找任何地方的經度,緯度和時區的詳細信息。如何找到任何地方的緯度經度和時區?

我怎樣才能一次獲得所有這些細節?

我們可以很容易找到經緯度,但我們怎麼才能得到那個地方的確切時區?

請問有誰能指導我?

謝謝。

回答

0

您可以通過使用

NSTimeZone* destinationTimeZone = [NSTimeZone systemTimeZone];

+0

或者如果你只想顯示時區名稱'[destinationTimeZone name]' – 2013-05-13 06:38:19

+0

是啊。但我怎樣才能得到世界上任何地方的時區。 – 2013-05-13 06:40:48

+1

好的,如果你有這個用途,那麼你需要使用一些網絡服務。看看這個http://stackoverflow.com/questions/41504/timezone-lookup-from-latitude-longitude – 2013-05-13 06:43:10

0

你是從CLLocationManager GET位置,你也來看看Geonames.org

這是一個免費的web服務,讓您從任何設備獲取時區獲取很多來自long/lat的信息

它們還爲GeoNames Webservices庫提供免費(和開源)Java客戶端(其他語言的庫也提供:紅寶石,蟒蛇,perl的,口齒不清......)

這裏的一些信息,你可以從長期獲取/緯度:(complete list of webservices here)

查找最近的地址

查找最近的路口

查找附近的街道

海拔時區

3

它看起來像你想這樣: -

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

對我而言,返回"Asia/Kolkata"

如果您使用的是systemTimeZone那麼它代表系統(設備)本身使用的時區。 localTimeZone返回一個對象,該對象表示應用程序的當前默認時區。

使用此API獲取數據並傳遞緯度和長度值。

Api for getting timeZone

+0

是的,但我想找到世界上任何時區的名稱。我怎麼能得到這個? – 2013-05-13 07:33:22

+0

@Nithin S:你有答案嗎? – Balu 2013-05-13 08:09:46

+0

@NithinS這是正確的答案,但沒有明確解釋。什麼陽光明媚的手段是,你應該首先獲得目標位置的緯度和經度,然後發送一個電話到該谷歌API網站,它將返回時區(如在示例中給出的鏈接)。忘了提及。一些Google服務在您可以撥打的電話數量和通話目的方面有限制。一定要閱讀這個特定API的細節。 – Pochi 2013-05-13 10:17:59

1

可以使用CoreLocation得到經度和緯度。

在您希望經緯度的.h類中添加此項。

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

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

而在你的.m文件

#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); 

} 

和當前時區您可以使用

NSTimeZone* currentTimeZone = [NSTimeZone systemTimeZone]; 
NSDateFormatter *dateFormatter = [dateFormat setTimeZone:currentTimeZone]; 
NSDate *rightNow = [NSDate date]; 
NSString *dateString = [dateFormatter stringFromDate:rightNow]; 
+0

Z:我想罰款世界上任何地方的時區而不是當前時區。或至少是世界上任何地點的時區名稱。有什麼方法可以找到? – 2013-05-13 07:30:23

+0

老兄當你的應用程序運行時,可以說倫敦,英格蘭,然後它會給這個特定地點的時區。 – 2013-05-13 07:35:23

+0

或者是你想製作一些他們在世界時鐘中使用的時區查找器?像這個http://www.timeanddate.com/time/map/ – 2013-05-13 07:36:41