IOS map (add a PIN)

Source: Internet
Author: User
Tags uikit

First, import the Mapkit.framework library file in the project

1 #import <UIKit/UIKit.h>23@interface Appdelegate:uiresponder < Uiapplicationdelegate>45 @property (Strong, Nonatomic) UIWindow *window; 6 7 @end
1 #import "AppDelegate.h"2 #import "RootViewController.h"3 @interfaceappdelegate ()4 5 @end6 7 @implementationappdelegate8 9 Ten-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchoptions { OneSelf.window =[[UIWindow alloc] initwithframe:[[uiscreen mainscreen] bounds]; A     //Override point for customization after application launch. -Self.window.backgroundColor =[Uicolor Whitecolor]; -      theSelf.window.rootViewController =[[Rootviewcontroller alloc] init]; -      - [Self.window makekeyandvisible]; -     returnYES; + } -  + @end
1 #import <UIKit/UIKit.h>23@interface  rootviewcontroller: Uiviewcontroller45@end
1 #import "RootViewController.h"2 #import<MapKit/MapKit.h>3 #import "YXYCAnation.h"4 5 @interfaceRootviewcontroller () <MKMapViewDelegate>6 7 @end8 9 @implementationRootviewcontrollerTen  One- (void) Viewdidload { A [Super Viewdidload]; -     //Initialize Mkmapview -Mkmapview *mapview =[[Mkmapview alloc] initwithframe:[[uiscreen mainscreen] bounds]; the     //Set up proxy -Mapview.Delegate=Self ; -     //set display current position -Mapview.showsuserlocation =YES; +     //Set the map display type -Mapview.maptype =Mkmaptypestandard; +     //latitude and longitude degree ACllocationcoordinate2d coord2d = {23.117000,113.27500}; at     //Display Range Accuracy -Mkcoordinatespan span = {0.01,0.01}; -     //Display Area -Mkcoordinateregion region ={Coord2d,span}; -     //Setting the display area for a map - [Mapview setregion:region animated:yes]; in [Self.view Addsubview:mapview]; -      to     //Create a Anation object +Cllocationcoordinate2d Showcoord = {23.117000,113.27500}; -Yxycanation *anation1 =[[Yxycanation alloc] initwithcoordinate2d:showcoord]; theAnation1.title =@"Yuexiu Park"; *Anation1.subtitle =@"Small title"; $ [Mapview Addannotation:anation1];Panax Notoginseng } -  the #pragmaMark-mkannotationview delegate- +-(Mkannotationview *) Mapview: (Mkmapview *) Mapview viewforannotation: (ID<MKAnnotation>) Annotation A { the     StaticNSString *identify =@"Annotian"; +Mkpinannotationview *annotationview = (Mkpinannotationview *) [Mapview dequeuereusableannotationviewwithidentifier:identify]; -     if(Annotationview = =Nil) { $         //Mkpinannotationview is a pin view $Annotationview =[[Mkpinannotationview alloc] initwithannotation:annotation reuseidentifier:identify]; -         //Set whether title view is displayed -Annotationview.canshowcallout =YES; the          -UIButton *button =[UIButton buttonwithtype:uibuttontypedetaildisclosure];Wuyi [button addtarget:self action: @selector (buttonaction:) forcontrolevents:uicontroleventtouchupinside]; theAnnotationview.rightcalloutaccessoryview =button; -     } WuAnnotationview.pincolor =mkpinannotationcolorred; -Annotationview.animatesdrop =YES; About      $     returnAnnotationview; - } -  -- (void) Buttonaction: (UIButton *) Sender A { +NSLog (@"Show Park Introduction"); the } -  $ @end
1 #import<Foundation/Foundation.h>2 #import<MapKit/MapKit.h>3 @interfaceYxycanation:nsobject<mkannotation>4 5 @property (nonatomic, assign) cllocationcoordinate2d coordinate;6@property (nonatomic, copy) NSString *title;7@property (nonatomic, copy) NSString *subtitle;8 9- (ID) Initwithcoordinate2d: (cllocationcoordinate2d) coordinate;Ten  One @end
1 #import "YXYCAnation.h"2 3 @implementationyxycanation4 5- (ID) Initwithcoordinate2d: (cllocationcoordinate2d) Coordinate6 {7Self =[Super init];8     if(Self! =Nil) {9_coordinate =coordinate;Ten     } One     returnSelf ; A } -  -  the @end

as follows:

IOS map (add a PIN)

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.