码迷,mamicode.com
首页 > 移动开发 > 详细

iOS地图中添加大头针

时间:2015-08-13 18:22:45      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

        首先,我们得新建一个遵守MKAnnotation的对象,并且拥有以下几个属性:

@interface LHAnnotation : NSObject<MKAnnotation>

// Center latitude and longitude of the annotion view.

// The implementation of this property must be KVO compliant.

@property (nonatomic, assign) CLLocationCoordinate2D coordinate;

// Title and subtitle for use by selection UI.

@property (nonatomic, copy) NSString *title;

@property (nonatomic, copy) NSString *subtitle;

然后了,在需要它的地方导入这个对象,LHAnnotation,就行了。

下面是主要的代码(纯代码,没有使用storyboard):

//  Created by 妖精的尾巴 on 15-8-13.

//  Copyright (c) 2015 妖精的尾巴. All rights reserved.

//


#import "ViewController.h"

#import <MapKit/MapKit.h>

#import "LHAnnotation.h"

@interface ViewController ()<MKMapViewDelegate>

@property(nonatomic,strong)MKMapView* mapView;

@end


@implementation ViewController


- (void)viewDidLoad

{

    [super viewDidLoad];

    [self setMap];

    LHAnnotation* annotation=[[LHAnnotation alloc]init];

    annotation.coordinate=CLLocationCoordinate2DMake(39.924115, 116.186063);

    annotation.title=@"石景山区";

    annotation.subtitle=@"领袖大厦B";

    [self.mapView addAnnotation:annotation];

}

-(void)setMap

{

    self.mapView=[[MKMapView alloc]init];

    self.mapView.frame=self.view.bounds;

    /**

     *mapType

     *

     * MKMapTypeStandard = 0,

       MKMapTypeSatellite,

       MKMapTypeHybrid

     */

    self.mapView.mapType=MKMapTypeStandard;

    /**

     *Set to YES to add the user location annotation to the map and start updating its location

     */

    self.mapView.showsUserLocation=NO;

    /**

     *Zoom and scroll are enabled by default.

     */

    self.mapView.scrollEnabled=YES;

    self.mapView.zoomEnabled=YES;

    /**

     *Rotate and pitch are enabled by default on Mac OS X and on iOS 7.0 and later.

     */

    self.mapView.pitchEnabled=YES;

    self.mapView.rotateEnabled=YES;

    [self.view addSubview:self.mapView];

}

运行程序截图如下 

技术分享

iOS地图中添加大头针

标签:

原文地址:http://my.oschina.net/iOSliuhui/blog/491948

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!