2012-02-08 2 views

답변

0

나를 위해 잘 된 속임수는 다음과 같습니다. 어느 시간대 식별자를 추출 할 수 있으며이 ID를 시간대로 사용할 수 있습니다.

CLLocation *location = [[CLLocation alloc] initWithLatitude:latitude longitude:longitude]; 

[geoCoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) { 

    if (error == nil && [placemarks count] > 0) { 

     placeMark = [placemarks lastObject]; 
     NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"identifier = \"[a-z]*\\/[a-z]*_*[a-z]*\"" options:NSRegularExpressionCaseInsensitive error:NULL]; 
     NSTextCheckingResult *newSearchString = [regex firstMatchInString:[placeMark description] options:0 range:NSMakeRange(0, [placeMark.description length])]; 
     NSString *substr = [placeMark.description substringWithRange:newSearchString.range]; 
     NSLog(@"timezone id %@",substr); 

    }]; 
+1

은 참고로이 예이 사과의 개인 프레임 워크입니다 – thedeveloper3124

+0

애플 전용 프레임 워크입니다,하지만 당신은 기본 프레임 워크에서 그것을 얻을 경우 그것은 오히려 타사 라이브러리를 사용하는 것보다 좋습니다. 가 https://github.com/Alterplay/APTimeZones/issues/2이 을 읽은 후 사용하십시오 : 아이폰 OS 업데이트에서이 파괴의 –

+0

기회는 :) 그래서 +1 – thedeveloper3124

2

나는 APTimeZones 라이브러리를 사용했습니다. 제 경우에는 특정 도시의 위도 경도에서 시간대와 국가 이름이 필요했습니다. 나는 그것이 어떻게 작동하는지 알기 위해 도서관을 조사했다. 실제로 JSON 형식의 데이터베이스를 가지고 있는데이 데이터베이스는 해당 시간대와 함께 모든 시간대를 포함합니다. lat를 입력으로 가져오고 모든 시간대의 lat의 거리를 입력 lat long과 비교하여 데이터베이스를 통해 반복합니다. 입력 위도와의 거리가 가장 짧은 시간대를 반환합니다.

큰 나라의 국경에있는 도시에서 문제가 발생했습니다.이 도시는 이웃 국가의 시간대를 반환했습니다. 국가 코드도 추출 했으므로 주변 국가가 있습니다.

그래서 Apple의 기본 프레임 워크는이 경우에 훨씬 좋습니다.

그리고 아래 코드는 나를 잘 처리했습니다.

CLLocation *location = [[CLLocation alloc] initWithLatitude:your_latitude longitude:your_longitude]; 
CLGeocoder *geoCoder = [[CLGeocoder alloc]init]; 
[geoCoder reverseGeocodeLocation: location completionHandler:^(NSArray *placemarks, NSError *error) 
{ 
CLPlacemark *placemark = [placemarks objectAtIndex:0]; 
NSLog(@"Timezone -%@",placemark.timeZone); 

//And to get country name simply. 
NSLog(@"Country -%@",placemark.country); 

}]; 
+0

타사 라이브러리가없는 가장 우아한 솔루션입니다! 나는 CLPlacemark에 timeZone 속성이 있다는 것을 믿을 수 없다. :) – PostCodeism

+0

네, 그럴만 한 가치가있었습니다. 해피 코딩 :) – Roohul

관련 문제