码迷,mamicode.com
首页 > Windows程序 > 详细

使用MapKit API现实用户当前位置 放置标注

时间:2015-03-21 11:16:51      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:mapkit   mkmapview   地图   标注   


注意:添加CoreLocation及MapKit框架;在Info.plist中添加NSLocationWhenInUseUsageDescription及提示信息


//
//  ViewController.m
//  MyAddressMap
//
//  Created by MQL on 15/3/20.
//  Copyright (c) 2015年 MQL. All rights reserved.
//

#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>

@interface ViewController ()<CLLocationManagerDelegate, MKMapViewDelegate>
{
    CLLocationManager *locationManager;
    id <MKAnnotation> annotation;
}

@property (nonatomic, weak) IBOutlet MKMapView *mapView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    
    //应用启动时的默认操作
    if (locationManager == nil) {
        
        locationManager = [[CLLocationManager alloc]init];
    }
    
    if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 8.0)
    {
        //设置定位权限 仅ios8有意义
        [locationManager requestWhenInUseAuthorization];// 前台定位
        
    }
    //应用启动时的默认操作
}

#pragma mark --MKMapViewDelegate

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    //放大地图
    userLocation.title = @"";
    MKCoordinateRegion regin = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 600, 600);
    [self.mapView setRegion:regin];
    
    //添加大头针
    if (annotation) {
        
        [self.mapView removeAnnotation: annotation];
    }
    
    MKPointAnnotation *point = [[MKPointAnnotation alloc]init];
    annotation = point;
    point.coordinate = userLocation.coordinate;
    point.title = @"北京市朝阳区广顺北大街33号院1号楼福码大厦B座12层";
    
    [self.mapView addAnnotation:point];
    
}


@end


使用MapKit API现实用户当前位置 放置标注

标签:mapkit   mkmapview   地图   标注   

原文地址:http://blog.csdn.net/qianlima210210/article/details/44513991

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