2014-09-27 126 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

相关问题