环境:系统版本:

OSX 10.10.2

Xcodel版本:7.1.1

功能:用自带地图实现查找,导航

1.首先需要在info.plist中添加NSLocationWhenInUseUsageDescription和NSLocationAlwaysUsageDescription两个属性

导入CoreLocation.framework框架

2.创建CLLocationManager类,启动定位功能

// 定位管理self.locationManager = [[CLLocationManager alloc]init];if (![CLLocationManager locationServicesEnabled]) {NSLog(@"定位服务当前未打开");return;}// 请求用户授权if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined) {[self.locationManager requestWhenInUseAuthorization];}else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse){// 设置代理self.locationManager.delegate = self;// 设置定位精度self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;// 定位频率,每隔多少米定位一次CLLocationDistance distance = 10.0; // 十米定位一次self.locationManager.distanceFilter = distance;// 启动跟踪定位[self.locationManager startUpdatingLocation];}

遵守CLLocationManagerDelegate代理,实现跟踪定位

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: 'Heiti SC Light';"><span style="line-height: normal; font-family: Menlo;">// </span>跟踪定位代理</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    CLLocation *location = [locations firstObject]; // <span style="line-height: normal; font-family: 'Heiti SC Light';">取出第一个位置</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    CLLocationCoordinate2D coordinate = location.coordinate; // <span style="line-height: normal; font-family: 'Heiti SC Light';">位置坐标</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">     NSLog(@"<span style="line-height: normal; font-family: 'Heiti SC Light';">经度:</span>%f,<span style="line-height: normal; font-family: 'Heiti SC Light';">纬度:</span>%f,<span style="line-height: normal; font-family: 'Heiti SC Light';">海拔:</span>%f,<span style="line-height: normal; font-family: 'Heiti SC Light';">航向:</span>%f,<span style="line-height: normal; font-family: 'Heiti SC Light';">行走速度:</span>%f",coordinate.longitude,coordinate.latitude,location.altitude,location.course,location.speed);</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    _jinddu = coordinate.longitude;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    _weidu = coordinate.latitude;</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: 'Heiti SC Light';"><span style="line-height: normal; font-family: Menlo;">    </span><span style="line-height: normal; font-family: Menlo;">//</span>如果不需要实时定位,使用完即使关闭定位服务</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    [_locationManager stopUpdatingLocation];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">}</p>

2.根据坐标取得地名

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: 'Heiti SC Light';"><span style="line-height: normal; font-family: Menlo;">// </span>根据坐标取得地名</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">-(void)getAddressByLatitude:(CLLocationDegrees)latitude longitude:(CLLocationDegrees)longitude{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    //<span style="line-height: normal; font-family: 'Heiti SC Light';">反地理编码</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    CLLocation *location=[[CLLocation alloc]initWithLatitude:latitude longitude:longitude];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    [_geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        CLPlacemark *placemark=[placemarks firstObject];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        NSLog(@"<span style="line-height: normal; font-family: 'Heiti SC Light';">详细信息</span>:%@",placemark.addressDictionary);</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    }];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">}</p>

3.根据地名确定地理坐标

<p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">-(void)getCoordinateByAddress:(NSString *)address{</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    //<span style="line-height: normal; font-family: 'Heiti SC Light';">地理编码</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    [_geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: 'Heiti SC Light';"><span style="line-height: normal; font-family: Menlo;">        </span><span style="line-height: normal; font-family: Menlo;">//</span>取得第一个地标,地标中存储了详细的地址信息,注意:一个地名可能搜索出多个地址</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        CLPlacemark *placemark=[placemarks firstObject];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo; min-height: 16px;">        </p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        CLLocation *location=placemark.location;//<span style="line-height: normal; font-family: 'Heiti SC Light';">位置</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        CLRegion *region=placemark.region;//<span style="line-height: normal; font-family: 'Heiti SC Light';">区域</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        NSDictionary *addressDic= placemark.addressDictionary;//<span style="line-height: normal; font-family: 'Heiti SC Light';">详细地址信息字典</span>,<span style="line-height: normal; font-family: 'Heiti SC Light';">包含以下部分信息</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *name=placemark.name;//<span style="line-height: normal; font-family: 'Heiti SC Light';">地名</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *thoroughfare=placemark.thoroughfare;//<span style="line-height: normal; font-family: 'Heiti SC Light';">街道</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *subThoroughfare=placemark.subThoroughfare; //<span style="line-height: normal; font-family: 'Heiti SC Light';">街道相关信息,例如门牌等</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *locality=placemark.locality; // <span style="line-height: normal; font-family: 'Heiti SC Light';">城市</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *subLocality=placemark.subLocality; // <span style="line-height: normal; font-family: 'Heiti SC Light';">城市相关信息,例如标志性建筑</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *administrativeArea=placemark.administrativeArea; // <span style="line-height: normal; font-family: 'Heiti SC Light';">州</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *subAdministrativeArea=placemark.subAdministrativeArea; //<span style="line-height: normal; font-family: 'Heiti SC Light';">其他行政区域信息</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *postalCode=placemark.postalCode; //<span style="line-height: normal; font-family: 'Heiti SC Light';">邮编</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *ISOcountryCode=placemark.ISOcountryCode; //<span style="line-height: normal; font-family: 'Heiti SC Light';">国家编码</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *country=placemark.country; //<span style="line-height: normal; font-family: 'Heiti SC Light';">国家</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *inlandWater=placemark.inlandWater; //<span style="line-height: normal; font-family: 'Heiti SC Light';">水源、湖泊</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSString *ocean=placemark.ocean; // <span style="line-height: normal; font-family: 'Heiti SC Light';">海洋</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        //        NSArray *areasOfInterest=placemark.areasOfInterest; //<span style="line-height: normal; font-family: 'Heiti SC Light';">关联的或利益相关的地标</span></p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">        NSLog(@"<span style="line-height: normal; font-family: 'Heiti SC Light';">位置</span>:%@,<span style="line-height: normal; font-family: 'Heiti SC Light';">区域</span>:%@,<span style="line-height: normal; font-family: 'Heiti SC Light';">详细信息</span>:%@",location,region,addressDic);</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">    }];</p><p style="margin-top: 0px; margin-bottom: 0px; font-size: 14px; line-height: normal; font-family: Menlo;">}</p>

使用苹果自带地图

1.根据单个地名在地图上定位

-(void)location{//地理编码[_geocoder geocodeAddressString:@"上海市" completionHandler:^(NSArray *placemarks, NSError *error) {CLPlacemark *clPlacemark=[placemarks firstObject];//获取第一个地标MKPlacemark *mkplacemark=[[MKPlacemark alloc]initWithPlacemark:clPlacemark];//定位地标转化为地图的地标NSDictionary *options=@{MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard)};MKMapItem *mapItem=[[MKMapItem alloc]initWithPlacemark:mkplacemark];[mapItem openInMapsWithLaunchOptions:options];}];
}

2.定位多个地名

- (void)listPlacemark
{//根据“北京市”进行地理编码[_geocoder geocodeAddressString:@"北京市" completionHandler:^(NSArray *placemarks, NSError *error) {CLPlacemark *clPlacemark1=[placemarks firstObject];//获取第一个地标MKPlacemark *mkPlacemark1=[[MKPlacemark alloc]initWithPlacemark:clPlacemark1];//注意地理编码一次只能定位到一个位置,不能同时定位,所在放到第一个位置定位完成回调函数中再次定位[_geocoder geocodeAddressString:@"郑州市" completionHandler:^(NSArray *placemarks, NSError *error) {CLPlacemark *clPlacemark2=[placemarks firstObject];//获取第一个地标MKPlacemark *mkPlacemark2=[[MKPlacemark alloc]initWithPlacemark:clPlacemark2];NSDictionary *options=@{MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard)};//MKMapItem *mapItem1=[MKMapItem mapItemForCurrentLocation];//当前位置MKMapItem *mapItem1=[[MKMapItem alloc]initWithPlacemark:mkPlacemark1];MKMapItem *mapItem2=[[MKMapItem alloc]initWithPlacemark:mkPlacemark2];[MKMapItem openMapsWithItems:@[mapItem1,mapItem2] launchOptions:options];}];}];
}

3.实现导航功能

-(void)turnByTurn{//根据“北京市”地理编码[_geocoder geocodeAddressString:@"北京市" completionHandler:^(NSArray *placemarks, NSError *error) {CLPlacemark *clPlacemark1=[placemarks firstObject];//获取第一个地标MKPlacemark *mkPlacemark1=[[MKPlacemark alloc]initWithPlacemark:clPlacemark1];//注意地理编码一次只能定位到一个位置,不能同时定位,所在放到第一个位置定位完成回调函数中再次定位[_geocoder geocodeAddressString:@"郑州市" completionHandler:^(NSArray *placemarks, NSError *error) {CLPlacemark *clPlacemark2=[placemarks firstObject];//获取第一个地标MKPlacemark *mkPlacemark2=[[MKPlacemark alloc]initWithPlacemark:clPlacemark2];NSDictionary *options=@{MKLaunchOptionsMapTypeKey:@(MKMapTypeStandard),MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving};//MKMapItem *mapItem1=[MKMapItem mapItemForCurrentLocation];//当前位置MKMapItem *mapItem1=[[MKMapItem alloc]initWithPlacemark:mkPlacemark1];MKMapItem *mapItem2=[[MKMapItem alloc]initWithPlacemark:mkPlacemark2];[MKMapItem openMapsWithItems:@[mapItem1,mapItem2] launchOptions:options];}];}];
}

地图实现地点查找和导航相关推荐

  1. Android 整合高德地图SDK实现 地图预览,定位,模拟导航

    一.准备工作 1. 到高德地图官方网申请key: 我的应用 | 高德控制台 2. 申请key方法请参考:获取Key-创建工程-开发指南-Android 地图SDK | 高德地图API 3. 出现的问题 ...

  2. Android 调用百度地图sdk 实现路线规划导航

    Android 调用百度地图sdk 实现路线规划导航 功能: 实现实时/需求定位 卫星地图查看 路况 周边poi检索 地点输入提示检索 驾驶 步行 公交 骑行路线规划 注:以上为实现的大概功能 ,接下 ...

  3. 高德地图2020最新版下载导航wince_导航定位错误致青城山严重拥堵,高德地图回应:已优化...

    钛媒体 TMTPost.com|科技引领新经济| ▎景区官方表示,错误导航问题已存在多年,景区多次与高德地图方联系,要求对青城前山景区导航路线进行修改优化,但均未果. 钛媒体编辑丨石万佳 钛媒体App ...

  4. 后端根据百度地图真实路径距离_导航软件哪家强?实测百度地图and高德地图哪个更靠谱...

    随着社会的不断发展,人们的生活越来越离不开地图导航,无论是开车出行还是到去到陌生的地方,我们都会用到手机地图.然而在众多导航软件中,使用最为广泛的就要属百度地图和高德地图了.但别看都是导航软件,其中差 ...

  5. 路痴福音!高德地图上线真AR步行导航,可实景指引

    2月8日消息,高德地图近日发布V10.76新版本,上线真AR步行导航,借助智能定位.地图导航与AR渲染等技术,可在真实拍摄的道路画面上,呈现更加直观的3D实景指引,帮助方向感不强的用户解决起步找方向难 ...

  6. python爬取地图地址_python爬取了高德地图一些地点的数据,爬出来数据大致情况如下:...

    python爬取了高德地图一些地点的数据,爬出来数据大致情况如下: 下面是基本流程: 1.注册成为高德地图API开发者,网址http://lbs.amap.com/(主要是获取自己的keywords ...

  7. 互联网快讯:百度地图第二代车道级导航上线;猿辅导推智能练习本布局教育智能硬件;vivo WATCH 2智能手表正式发布

    国内要闻 中国稀土集团有限公司在江西赣州挂牌成立,中铝集团.中国五矿.赣州稀土集团等参股: 华为举办冬季旗舰新品发布会,华为P50 Pocket旗舰折叠屏手机.AITO问界M5智能汽车.华为WATCH ...

  8. Android百度地图(六)自定义导航路线规划

    Android百度地图(六)自定义导航路线规划 兴奋加激动... 本文代码在http://blog.csdn.net/xyzz609/article/details/51959767的基础上进一步修改 ...

  9. 百度地图之九如何在一个地图上显示多条导航路线

    分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! 如何在一 ...

最新文章

  1. Lock和synchronized比较详解
  2. salt '*' state.highstate 报错找不到文件,环境如下No Top file or master_tops data matches found....
  3. tomcat实现session集群及tomcat+memcached共享session存储(四)
  4. 后台导出大量数据超时报 nginx404错误
  5. mysql非主键索引_主键索引和非主键索引的区别
  6. linux shadow 时间,Linux Shadow-Password-HOWTO - 7. 将 Shadow Suite 放进来使用(1)
  7. python读取xml文件内容_python读取xml文件
  8. 使用C#客户端访问FTP服务的一个解决方案
  9. 小米高管:已投大量精力研发手机AI芯片,造不造还没定
  10. raw转bmp程序c语言,求指导,如何用c语言实现读取*.raw格式图像
  11. Mac Mysql 基本操作命令
  12. android APN的打开与关闭
  13. 2022年PMP培训机构如何挑选?哪家好?
  14. DBeaver执行SQL脚本
  15. oracle大杂烩(二)
  16. 为什么边缘概率密度是联合概率密度的积分_解读奥运积分排名:石宇奇为何第13 林丹谌龙未入前16...
  17. dubbo SPI机制与@Adaptive自适应扩展机制
  18. mybatis原理分析(五)---参数处理
  19. 搭建java环境和java学习
  20. PoE交换机的多种连接方式 PoE交换机的4种连接方式

热门文章

  1. C语言学习笔记10-指针(动态内存分配malloc/calloc、realloc、释放free,可变数组实现;Tips:返回指针的函数使用本地变量有风险!;最后:函数指针)
  2. 在网页上加载百度地图
  3. JavaScript 开发的45个技巧2
  4. Oracle学习之建表
  5. oracle数据库定时每天自动备份语句,Oracle数据库定时自动备份
  6. 什么是高维组合特征?
  7. 阿里MNS、OSS 和亚马逊 SQS、S3对比
  8. 请把我埋在新闻联播里
  9. 全新的Unity移动游戏优化解决方案
  10. EasyAR-Web手把手基于官方demo的实现