从日历事件(EKCalendarItem/EKEvent)检索位置lat/long(CLLocationCoordinate2d)
从日历事件(EKCalendarItem/EKEvent)检索位置lat/long(CLLocationCoordinate2d),calendar,location,ios8,ekevent,cllocationcoordinate2d,Calendar,Location,Ios8,Ekevent,Cllocationcoordinate2d,EKCalendarItem具有属性“Location”,但它是一个NSString。 新的iOS8功能为事件显示了一个很好的映射,因此必须在EKCalendarItem上附加一个CLLocationCoordinate2D,对吗? 我在哪里可以找到此CLLocationCoordinate2D?EKCalendarItem不包含任何CLLocationCoordinate2D属性,它具有location,即您在问题中提到的NSString 您可以使用location属性获取坐标。您可以使用Co
EKCalendarItem
具有属性“Location”,但它是一个NSString
。
新的iOS8功能为事件显示了一个很好的映射,因此必须在EKCalendarItem
上附加一个CLLocationCoordinate2D
,对吗?
我在哪里可以找到此
CLLocationCoordinate2D
?EKCalendarItem
不包含任何CLLocationCoordinate2D属性,它具有location
,即您在问题中提到的NSString
您可以使用location
属性获取坐标。您可以使用CoreLocation
framework的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
的location属性检索到的位置字符串。默认iCal应用程序必须执行类似操作,希望这对您有所帮助。这将满足您的需要:
for (EKEvent *calEvent in self.allMyEvents) {
EKStructuredLocation *location = (EKStructuredLocation *)[calEvent valueForKey:@"structuredLocation"];
if (location) {
}
}
我在eventkit框架中没有看到什么新的东西谢谢Bhumit,地图位置坐标清楚地连接到事件,所以我想知道它存储在哪里?谢谢Bhumit。是的,我在我的一些应用程序中使用了它,但是[placemarks objectAtIndex:0];将不总是正确的位置。我认为该位置存储在EKStructuredLocation中,只需进行一些测试,以了解如何到达该位置。
EKStructuredLocation
是EKAlarm
的属性,因此我怀疑它是否用于日历项,无论如何,我会环顾四周,希望我们能找到更好的方法来实现它!NSArray*eventList=[self.eventStore eventsMatchingPredicate:fetchCalendarEvents];对于(int i=0;istructuredLocation
用于EKEvent
@属性(复制,非原子)EKStructuredLocation*structuredLocation的;父EKCalendarItem中的private,因此必须解析[EKEvent description]。希望这件事能尽快公之于众。。。。