系统地图的用法

news/2024/7/5 6:35:38

1,  引用框架  CoreGraphics.framework     MapKit.framework  CoreLocation.framework

2 导入主头文件 iOS5之后不需要手动导入

#import <CoreLocation/CoreLocation.h>
#import <MapKit/MapKit.h>
(1)MapKit :用于地图展示
(2)CoreLocation :用于地理定位 

CoreLocation框架使用须知 

(1)  Corelocation框架中所有数据类型的前缀都是CL
(2)  Corelocation中使用的CLLocationManager对象来做用户定位

这是初始化
locationManager = [[CLLocationManager alloc] init];//初始化
    locationManager.delegate = self;//委托自己
    locationManager.desiredAccuracy = kCLLocationAccuracyBest;//精度设定
    [locationManager startUpdatingLocation];//开启位置更新


定义经纬坐标

CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude=21.238928;  经度
theCoordinate.longitude=113.313353;纬度


//
//  ViewController.m
//  MapStudy
//
//  Created by lanouhn on 15/3/21.
//  Copyright (c) 2015 niutiantian. All rights reserved.
//

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

@interface ViewController ()<MKMapViewDelegate, CLLocationManagerDelegate[CDATA[]]>
{
        //用来做用户定位
    CLLocationManager *locationManeger;
    CLLocation *location;
    CLGeocoder *geocoder; //反向地理编码
    CLLocationCoordinate2D coordinate; //地理位置坐标
    MKMapView *_mapView;
    
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
        //添加地图
    _mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];
    _mapView.delegate = self;
    [self.view addSubview:_mapView];
    
    
        //定位管理器
    locationManeger = [[CLLocationManager alloc] init];
        //定位管理器没有打开
    if (![CLLocationManager locationServicesEnabled]) {
        NSLog(@"请打开定位");
        return;
    }
    
        //请求用户授权
        //kCLAuthorizationStatusNotDetermined 未授权
        //kCLAuthorizationStatusAuthorizedWhenInUse 授权
    if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {
        [locationManeger requestWhenInUseAuthorization];     } else if ([CLLocationManager authorizationStatus]== kCLAuthorizationStatusAuthorizedWhenInUse) {             //设置代理         locationManeger.delegate = self;         locationManeger.desiredAccuracy = kCLLocationAccuracyBest;//精度设定         [locationManeger startUpdatingLocation]; //开启位置更新     }               _mapView.userTrackingMode = YES;//用户追踪当前位置         //设置地图类型     _mapView.mapType = MKMapTypeStandard;              //coordinate.latitude  coordinate.latitude  经度 纬度 //    CLLocation *location = [[CLLocation alloc] initWithLatitude:coordinate.latitude longitude:coordinate.latitude ];           } #pragma mark - MKMapViewDelegate #pragma mark - CLLocationManagerDelegate - (void)locationManager:(CLLocationManager *)manager      didUpdateLocations:(NSArray *)locations {     location = [locations firstObject];     coordinate = location.coordinate;         //地理位置反编码     geocoder = [[CLGeocoder alloc] init];     [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {         CLPlacemark *placeMark = [placemarks firstObject];         NSLog(@"%@", placeMark.addressDictionary);     }];         //添加标记大头针     [self addAnnotation];      } - (void)addAnnotation {     NSLog(@"%f", coordinate.latitude);     Annotation *annotation1 = [[Annotation alloc] init];     annotation1.title = @"CMJ Studio";     annotation1.subTitle = @"Kenshin Cui's Studios";     annotation1.coordinate = coordinate;     [_mapView addAnnotation:annotation1];      } -(void)viewWillAppear:(BOOL)animated {     [super viewWillAppear:animated];     [locationManeger stopUpdatingLocation]; } - (void)didReceiveMemoryWarning {     [super didReceiveMemoryWarning];     // Dispose of any resources that can be recreated. } @end #import <Foundation/Foundation.h> #import <MapKit/MapKit.h> @interface Annotation : NSObject<MKAnnotation[CDATA[]]> @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *subTitle; @property (nonatomic, assign) CLLocationCoordinate2D coordinate; @end

 

转载于:https://www.cnblogs.com/tian-sun/p/4356255.html


http://www.niftyadmin.cn/n/1944131.html

相关文章

find / -name *.py | xargs grep domain | wc -l

http://world77.blog.51cto.com/414605/209125 http://blog.csdn.net/windone0109/article/details/2817792 查找目录&#xff1a;find /&#xff08;查找范围&#xff09; -name 查找关键字 -type d查找文件&#xff1a;find /&#xff08;查找范围&#xff09; -name 查找关键…

Fiddler学习基础(一)

Fiddler官方网站及下载地址&#xff1a;http://www.telerik.com/fiddler 1. Fiddler原理&#xff1a; 作为系统代理&#xff0c;所有的来自微软互联网服务&#xff08;WinInet&#xff09;的http请求再到达目标Web服务器的之前都会经过Fiddler&#xff0c;同样的&#xff0c;所…

Nginx 代理配置

nginx 正向http代理配置 需要用户名和密码认证 生成密码文件&#xff1a; linux需要安装&#xff1a; #yum -y install httpd-tools生成密码文件&#xff1a; #htpasswd -c /usr/local/nginx/conf/pwd/passwd 用户名输入密码重新输入密码 server配置&#xff1a; 在conf的目录下…

mysql日期排序YMD_MySQL datetime字段查询按小时:分钟排序

我有这样一张桌子&#xff1a;id date_time1 2/11/2013 7:052 2/11/2013 7:003 2/12/2013 7:004 2/14/2013 7:005 2/16/2013 7:006 2/17/2013 7:007 2/12/2013 7:058 2/14/2013 7:059 2/15/2013 7:0510 2/16/2013 7:0511 2/17/2013 7:0512 2/13/2013 7:0013 2/15/2013 7:0014 2…

JAVA中类、实例与Class对象

已同步更新至个人blog&#xff1a;http://dxjia.cn/2015/08/java-class-object/ 类 类是面向对象编程语言的一个重要概念&#xff0c;它是对一项事物的抽象概括&#xff0c;可以包含该事物的一些属性定义&#xff0c;以及操作属性的方法。面向对象编程中&#xff0c;我们都是以…

linux sort 命令详解(转载)

转载&#xff1a;http://www.cnblogs.com/51linux/archive/2012/05/23/2515299.html#3374576 sort是在Linux里非常常用的一个命令&#xff0c;管排序的&#xff0c;集中精力&#xff0c;五分钟搞定sort&#xff0c;现在开始&#xff01; 1 sort的工作原理 sort将文件的每一行作…

Mac安装SSHFS挂载远程服务器上的文件夹到本地

一、安装SSHFUS sshfs依赖于fuse&#xff0c;所以需要先安装fuse&#xff0c;这两个软件都可以在https://osxfuse.github.io/下载到。 注意安装顺序。 二、挂载文件夹到本地 输入一下命令&#xff1a; sshfs jerryqi8.8.8.8:/var/www/html /Users/jerryqi/Desktop/Library-Stag…

mysql用户权限分配_Mysql用户添加及权限分配

Mysql用户添加及权限分配格式&#xff1a;grant [PRIVILEGES] on [databaseName.tableName] to [userName][host] identified by [password] with grant option;eg1: grant select on mysql.user to wqhlocalhosteg2:GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP ON expen…