IOS mkannotation Protocol add annotations to maps

Source: Internet
Author: User

Add map annotations, this need to use the Mkannotation this Protocol, mainly has two uilabel types of attributes, title and subtitle, when the user clicks on the heart Grow fonder needle will be displayed, such as: Google Maps implementation of the three added annotations-Tergol -Tergol's blog about the operation is like this, first define a class that inherits the Mkannotation, when the need to add annotations, based on the current region and other information, instantiate a pair of image, And then addannotation it up to GoogleMap. In order to implement mkannotation we redefine a class to operate. The NSObject class for the new objectiv-c. h header file #import <Foundation/Foundation.h> #import <CoreLocation/CoreLocation.h> # Import <MapKit/MapKit.h> @interface Mapannotations:nsobject <mkannotation>{cllocationcoordinate2d  coordinate;//this, in the map, is the center point.   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 source file #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 well, with this class, we can instantiate its image in the data update, and then add it to the Mkmapview instance, as follows: Mapannotations=[[mapannotations Alloc] Initwithcoordinate:loc]; [email protected] "TEST"; [email protected] "have a try"; [Map addannotation:mapannotations]; [Mapannotations release];

IOS mkannotation Protocol add annotations to maps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.