2014-09-27 59 views
2

EKCalendarItem具有「位置」屬性,但它是NSString。 新的iOS8功能顯示了一個不錯的活動地圖,因此必須有CLLocationCoordinate2D附加到EKCalendarItem,對嗎? 我在哪裏可以找到這CLLocationCoordinate2D從日曆事件(EKCalendarItem/EKEvent)中檢索位置lat/long(CLLocationCoordinate2d)

+0

沒有什麼新的我在eventkit框架看 – 2014-09-27 06:13:40

+0

感謝Bhumit,地圖座標位置明顯與事件,所以我不知道它被存儲在哪裏? – 2014-09-27 06:57:02

回答

5

這應該得到你所需要的:

for (EKEvent *calEvent in self.allMyEvents) { 

    EKStructuredLocation *location = (EKStructuredLocation *)[calEvent valueForKey:@"structuredLocation"]; 

    if (location) { 

    } 

} 
0

EKCalendarItem不包含任何CLLocationCoordinate2D屬性它具有location這就是NSString正如您在您的問題中提到的。

您可以使用location屬性來獲得座標。您可以使用CoreLocation框架的CLGeocoder從字符串中獲取座標。

您可以使用此代碼。

CLGeocoder *geocoder = [[CLGeocoder alloc] init]; 
[geocoder geocodeAddressString:locationString completionHandler:^(NSArray *placemarks, NSError *error) { 
    if([placemarks count]) { 
     CLPlacemark *placemark = [placemarks objectAtIndex:0]; 
     CLLocation *location = placemark.location; 
     CLLocationCoordinate2D coordinate = location.coordinate; 
     NSLog(@"coordinate = (%f, %f)", coordinate.latitude, coordinate.longitude); 

    } 
}]; 

這裏locationString是從EKCalendarItem的位置屬性中檢索到的位置字符串。默認的iCal應用程序必須做類似的事情,希望這可以幫助你。

+0

謝謝Bhumit。是的,我在一些應用中使用了這個功能,但[placemarks objectAtIndex:0];並不總是正確的位置。我認爲該位置存儲在EKStructuredLocation https://developer.apple.com/LIBRARY/IOS/documentation/EventKit/Reference/EKStructuredLocationClassRef/index.html#//apple_ref/occ/cl/EKStructuredLocation只需做一些測試即可找出如何去... – 2014-10-01 02:26:11

+0

'EKStructuredLocation'是'EKAlarm'的財產所以我懷疑它是用於日曆項目,反正我們不希望看到周圍希望我們有更好的方式來實現這個 – 2014-10-01 05:16:28

+1

發現它! NSArray * eventList = [self.eventStore eventsMatchingPredicate:fetchCalendarEvents]; for(int i = 0; i 2014-10-01 08:26:34

相關問題