zoukankan      html  css  js  c++  java
  • 系统地图的用法

    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

     
  • 相关阅读:
    手机端上传图片及java后台接收和ajaxForm提交
    JEECG中datagrid方法自定义查询条件
    微信分享到朋友圈按钮 右上角提示
    Js获取后台集合List的值和下标的方法
    redis系列之数据库与缓存数据一致性解决方案
    替换{0}为指定的字符串(MessageFormat)
    java中对array数组的常用操作
    面试题-Java Web-网络通信
    你应该知道的JAVA面试题
    各大互联网公司java开发面试常问问题
  • 原文地址:https://www.cnblogs.com/tian-sun/p/4356255.html
Copyright © 2011-2022 走看看