2013-03-12 196 views
0

我已經添加了地圖視圖,並添加了需要的map-kit框架工作和核心位置框架,使用iOS6,我添加了這些方法,但沒有獲取當前座標,因此我可以顯示gps跟蹤指標。從CLLocationManager獲取座標

下面是代碼:地圖

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateLocations:(NSArray *)locations { 

    CLLocation* location = [locations lastObject]; 

    NSLog(@"first time -- locations.count = %d", locations.count); 

    NSDate* eventDate = location.timestamp; 
    NSTimeInterval howRecent = [eventDate timeIntervalSinceNow]; 
    if (abs(howRecent) > 15.0) { 
     NSLog(@"latitude %+.6f, longitude %+.6f\n", 
      location.coordinate.latitude, 
      location.coordinate.longitude); 
    } 
} 

它給我的默認值(北緯37.785834,-122.406417經度),而不是我的地方的當前位置。

+0

如果您在模擬器中試用它,您將獲得默認值。您必須在設備上運行代碼才能獲得實際的座標值。 – 2013-03-12 04:31:50

+0

非常感謝你Vidya Murthy,還有一件事,我有閱讀reywenderlich教程,他下載了一些文件,以顯示谷歌地圖中的街道或路徑使用gps進行跟蹤,這是必需的。 – terminator 2013-03-12 04:38:32

+0

我想加入你的進一步討論,我的Gmail郵箱[email protected]給你的鏈接郵件 – terminator 2013-03-12 04:45:53

回答

1

如Vidya所述,要獲得您的位置的實際值,您需要嘗試使用真實設備。要測試您是否正確設置,請從模擬器中選擇一些位置,並查看座標是否反映了這些更改。

enter image description here

+0

thans你,我應該需要添加其他文件,以顯示使用GPS設備上的追蹤路徑。 – terminator 2013-03-12 04:43:55

+0

你是什麼意思追蹤路徑?如果你的意思是在地圖上顯示它,你可以看看適用於iOS的'MapKit'框架。 – yeesterbunny 2013-03-12 04:46:21

+0

我正在實施計算從當前位置到目的地位置的步行路徑的項目中的GPS,並顯示路徑。 – terminator 2013-03-12 04:49:04