iOS MKAnnotation協議為地圖添加註解

來源:互聯網
上載者:User

標籤:ios mkannotation協議   為地圖添加註解   

添加地圖註解,這個需要用到MKAnnotation這個協議,主要有兩個UILabel類型的屬性,title和subtitle,當使用者點擊小別針時候就會把相關資訊顯示出來,如:Google地圖實現之三添加註解 - tergol - tergol的部落格 大概的操作是這樣的,先定義一個繼承了MKAnnotation的類,第當需要加上註解的時候,就根據當前的region等資訊,執行個體化出一個對像,然後把它addAnnotation到googleMap上去就可了。為了實現MKAnnotation我們重新定義一個類來操作。建立objectiv-c的NSObject類.h標頭檔#import <Foundation/Foundation.h>#import <CoreLocation/CoreLocation.h> #import <MapKit/MapKit.h> @interface MapAnnotations : NSObject <MKAnnotation>{CLLocationCoordinate2D coordinate;//這個表示一點,在map中就是中心點。  NSString *subtitle;   NSString *title; }-(id)initWithCoordinate:(CLLocationCoordinate2D) coordinate;@property (nonatomic, readonly) CLLocationCoordinate2D coordinate;@property (nonatomic, retain) NSString *subtitle; @property (nonatomic, retain) NSString *title; @end.m源檔案#import "MapAnnotations.h"@implementation MapAnnotations@synthesize coordinate;@synthesize title;@synthesize subtitle;-(id)initWithCoordinate:(CLLocationCoordinate2D) c{coordinate=c;NSLog(@"%f,%f",c.latitude,c.longitude);return self;}- (void) dealloc  {[title release];[subtitle release];[super dealloc];}@end好了,有了這個類,我們就可以在資料更新的地方,執行個體化它的對像,然後加在MKMapview的執行個體上,就可以了,如下:mapAnnotations=[[MapAnnotations alloc] initWithCoordinate:loc];[email protected]"TEST";[email protected]"have a try";[map addAnnotation:mapAnnotations];[mapAnnotations release];

iOS MKAnnotation協議為地圖添加註解

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.