2015-04-03 118 views
0

我在Apple關注開發新的,並希望在Apple關注整合的蘋果地圖中,只是想表明我的當前位置,但我每次加載模擬器的界面我得到了屏幕像下面的時間。任何幫助可以欣賞。如何在蘋果手錶中集成蘋果地圖?

enter image description here

-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 
    { 
     CLLocation* loc = [locations lastObject]; 
     CLLocationCoordinate2D myLocationCoordinate2D = loc.coordinate; 
     [self.demoMap setRegion:MKCoordinateRegionMake(myLocationCoordinate2D, MKCoordinateSpanMake(0.0,0.0))];//set map region 
     [self.demoMap addAnnotation:myLocationCoordinate2D withPinColor:WKInterfaceMapPinColorGreen];// set pin on map 
     [locationManager stopUpdatingLocation]; 
    } 

#pragma mark - CLLocation Manager 

-(void)startTrackingCurrentLcoation:(BOOL)forTrip 
{ 
    locationManager = [[CLLocationManager alloc] init]; 
    locationManager.delegate = self; 
    locationManager.desiredAccuracy = kCLLocationAccuracyBest; 
    [locationManager requestAlwaysAuthorization]; 

    CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; 
    if (status == kCLAuthorizationStatusAuthorizedAlways || status == kCLAuthorizationStatusAuthorizedWhenInUse) 
    { 
     NSLog(@"%@ Start tracking current location", self); 
     [locationManager startUpdatingLocation]; 


    } 
} 
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status 
{ 
    status = [CLLocationManager authorizationStatus]; 
    if (status == kCLAuthorizationStatusDenied) 
    { 
     NSString *message = @"To use background location you must turn on 'Always' in the Location Services Settings"; 
     NSLog(@"%@",message); 
    } 
    else if (status == kCLAuthorizationStatusNotDetermined) 
    { 
     [locationManager requestAlwaysAuthorization]; 
    } 
    else 
    { 
     [locationManager startUpdatingLocation]; 
    } 

} 
+0

嗨,@Chirag可以請你添加代碼,這樣我可以幫你... – 2015-04-03 13:10:38

+0

嗨,@JayMehta我編輯我的問題 – 2015-04-03 14:21:14

+0

:1)增加更多的代碼(哪裏外景經理上手等)或2)添加一些日誌輸出,顯示其值傳遞到這個功能以及它是如何經常被稱爲。 – stk 2015-04-03 21:07:46

回答

4

請點擊此鏈接https://trymakedo.wordpress.com/tag/wkinterfacemap/

檢查的天氣讓你的當前位置座標傳遞給region.Test通過提供預定義的座標..

+0

非常有幫助完整鏈接@Elalgo麪包車 – 2015-04-04 14:27:13

+0

在那個鏈接只有一個錯誤在那裏,是沒有** ** setMapRect方法,但實際的方法是** ** setVisibleMapRect – 2015-04-04 14:37:22

+0

Ya..sry我忘了提及! – Elangovan 2015-04-06 04:58:31

1

我剛剛試了一下自己,有這許多陷阱。

我入侵了一個演示項目,你可以在這裏找到: https://github.com/sticksen/WatchKit-Map-Sample-Project

清單:

  • 一定要申請授權位置服務,並開始用戶之後更新位置已授予訪問權限。
  • 如果授權已經批准,可以開始更新位置馬上

現在最糟糕的部分:

  • 你的主要target's(其中isn't的WatchKit目標,只是爲了說清楚!)Info.plist中必須有一個名爲NSLocationWhenInUseUsageDescriptionNSLocationAlwaysUsageDescription(取決於你要求什麼樣的認證),它作爲值爲什麼要使用位置服務有一個描述字符串的關鍵。如果沒有在Info.plist中設置此項它不需額外工作
+0

感謝您的回答,但在演示中我面臨同樣的問題。我的主要部分是在地圖上顯示位置,它會繼續顯示在演示屏幕上方。即使我通過靜態位置。 – 2015-04-04 05:26:31

+0

對不起,但我不完全理解你的全部句子。 '它在屏幕上方繼續顯示'是什麼意思?你能截取它的截圖嗎?另外,我假設你有Xcode版本6.2(6C131e)。 – stk 2015-04-04 08:35:57

+0

此外,你必須接受的對位置服務的手機模擬器(不是手錶模擬器)的授權請求,於是有了上看看。你有沒有這樣做,對話框彈出?嘗試重置模擬器'重置內容和設置'並重新執行。 – stk 2015-04-04 08:41:54