2013-05-18 74 views
-1

我一直在使用核心數據來保存用戶在表格視圖中不同時間的位置。現在我可以在不同時間獲取位置詳細信息(主要是座標),我想繪製MapView上每次可用的座標(不疊加,只是單點指向當時的位置) 。我有座標(一個緯度和一個經度值)可用,但我想知道如何在MapView上繪製它們。使用保存的GPS座標從CLLocation在iPhone上繪製地圖

只是簡單地提出我的問題,如何在plotview上繪製座標?

我剛剛瀏覽過所以我無法找到能夠解決我的問題的確切解決方案!任何幫助都感激不盡。

謝謝你的時間!

Regards,

Raj。

+0

你有沒有看蘋果公司在其網站上的示例代碼? – Craig

+0

嘿克雷格!我其實在Apple的網站上查看了iOS的核心數據教程。它實際上說如何保存位置數據並刪除它們。但是,我仍然在尋找一個處理核心位置和Mapkit的緊密例子。這可能會訣竅..謝謝:) – Raj0689

+1

我懷疑你缺少的是,在地圖上顯示的東西被稱爲「註釋」,所以如果你搜索「如何顯示在MKMapView註釋」你會得到大量的結果。如果他們不夠清楚,你應該閱讀蘋果文檔中的「註釋地圖」部分(http://developer.apple.com/library/ios/#DOCUMENTATION/MapKit/Reference/MKMapView_Class/MKMapView/MKMapView.html ) – Craig

回答

0

在MKAnnotation的幫助下,可以解決這個問題。感謝@Craig和Vishal Kurup!

創建一個註釋類作爲NSObject的子類。

在Annotation.h:

@interface Annotation : NSObject <MKAnnotation> 

@property (nonatomic, assign) CLLocationCoordinate2D coordinate; 
@property (nonatomic, assign) NSString *title; 
@property (nonatomic, assign) NSString *subtitle; 

@end 

應該符合MKAnnotation和三個屬性是符合MKAnnotation上課的時候都需要的人。聲明它們並將它們合成到.m文件中。

在MapHistoryViewController實現文件中,我們需要添加幾行代碼來查看所需座標處的註釋。

MapHistoryViewController.m:

@interface MapHistoryViewController(){ 
    CLLocationCoordinate2D annotationCoord; 
    Annotation *annotation; 
} 

@end 

@implementation MapHistoryViewController 

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

// To define coordinate for the annotation 
    annotationCoord.latitude = mapHistoryLocation.coordinate.latitude; 
    annotationCoord.longitude = mapHistoryLocation.coordinate.longitude; 

    annotation = [Annotation alloc]; 
    annotation.coordinate = annotationCoord; 
    annotation.title = streetAnnotation; 

    // to display the annotation 
    [self.mapHistoryView addAnnotation:annotation]; 
// where mapHistoryView is my MKMapView object 
} 

//You can set the region too, if you want the map to be focused on the coordinates you have provided 
//Hope this will help the people with the same question :)