2014-11-13 15 views
5

NSString konumu değil, enlem ve boylam ile konum nasıl eklenir, böylece Takvim'de de bir harita gösteriliyor?EKEvent IOS Takvim konumuna ekle konum:

<EKCalendarItem> 

https://developer.apple.com/LIBRARY/ios/documentation/EventKit/Reference/EKCalendarItemClassRef/index.html#//apple_ref/occ/instp/EKCalendarItem/location

@property(nonatomic, copy) NSString *location; 

Kodu:

EKEventStore *store = [[EKEventStore alloc] init]; 
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { 
    if (!granted) { return; } 
    EKEvent *event = [EKEvent eventWithEventStore:store]; 
    event.title = @"Event Title"; 
    event.startDate = [NSDate date]; //today 
    event.endDate = [event.startDate dateByAddingTimeInterval:60*60]; //set 1 hour meeting 
    [email protected]"Note"; 
    [email protected]"Eiffel Tower,Paris"; //how do i add Lat & long/CLLocation? 
    event.URL=[NSURL URLWithString:shareUrl]; 
    [event setCalendar:[store defaultCalendarForNewEvents]]; 
    NSError *err = nil; 
    [store saveEvent:event span:EKSpanThisEvent commit:YES error:&err]; 
    NSString *savedEventId = event.eventIdentifier; //this is so you can access this event later 
}]; 

Example

+0

ans verilen yapıyor deneyin http://stackoverflow.com/questions/16647996/get-location- latitude-boylam-in-ios adı – Revinder

+0

Bunun için bir çözüm buldunuz mu? Aynı tekne üzerinde Im – jsetting32

+0

@ jsetting32 Hala hiçbir çözüm, belki mümkün değil düşünüyorum: P – Metalhead1247

cevap

0

SetValue kullanmak mümkün olabilir: ForKey: EKEvent bir EKStructuredLocation oluşturduktan sonra, anahtar 'structuredLocation'

5

Bunun için herhangi bir belge olmaması oldukça garip bir durumdur, ancak takvim etkinliğine coğrafi konum ekleme yönteminiz budur.

EKStructuredLocation* structuredLocation = [EKStructuredLocation locationWithTitle:@"Location"]; // locationWithTitle has the same behavior as event.location 
CLLocation* location = [[CLLocation alloc] initWithLatitude:0.0 longitude:0.0]; 
structuredLocation.geoLocation = location; 

[event setValue:structuredLocation forKey:@"structuredLocation"]; 
+0

Bunun işe yaradığından şüphe etmiyorum. Ancak dokümantasyon, Geofencing konumlarını ayarlamak için EKStructuredLocation'ın kullanılmasından bahseder. Bu çözümle ortaya çıkabilecek sorunlar nelerdir? – SpacyRicochet

+1

@spacyRicochet - Bu yöntemle herhangi bir sorunum olmadı. Ne yaptığımdan, takvim etkinliğinize bir harita eklemek için tek çözüm budur. Gerçekten, sorunun belgelerin güncellenmesi gerektiğine inanıyorum. Ya bu işlevselliği uyguladılar ve bu bir hataydı ya da sadece belgelerine eklemeyi unutmuşlardı. Her şeye rağmen çalışıyor. –

+0

Benim için düzgün çalışmıyor gibi görünüyor, ancak Simulator bunu beğenmiyor olabilir. Daha sonra cihazda deneyeceğim. – SpacyRicochet

7

mülkiyet structuredLocation EKEvent dokümantasyon söz etmez, ancak structuredLocation EKEvent public üst dosyada mevcut etmez ve Xcode içine kontrol edebilirsiniz rağmen, iOS 9 mevcuttur. şöyle Gerek iOS sonra 9.

Swift versiyonunu ayarlamak için KVC kullanmak:

let location = CLLocation(latitude: 25.0340, longitude: 121.5645) 
let structuredLocation = EKStructuredLocation(title: placeName) // same title with ekEvent.location 
structuredLocation.geoLocation = location 
ekEvent.structuredLocation = structuredLocation 
İlgili konular