iOS:地图:MapKit和CoreLocation
地图:MapKit和CoreLocation
#import <MapKit/MapKit.h>
#import <CoreLocation/CoreLocation.h>
添加显示地图的MKMapView控件 :
地图的类型 :



如何添加大头针(地标):

@interface MyAnnotation : NSObject <MKAnnotation>
@property (nonatomic, assign) CLLocationCoordinate2D coordinate;
@property (nonatomic, copy) NSString *title;
@property (nonatomic, copy) NSString *subtitle;
@end
<2>添加Annotation:
MyAnnotation *anno = [[MyAnnotation alloc] init];
anno.title = @“中国";
anno.subtitle = @“北京”;
//经度和纬度
anno.coordinate = CLLocationCoordinate2DMake(40, 110);
//添加大头针到地图中
[_mapView addAnnotation:anno];
// 让地图挪动到对应的位置(经纬度交叉处)
[_mapView setCenterCoordinate:anno.coordinate animated:YES];
自定义大头针:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
static NSString *ID = @"anno";
MKPinAnnotationView *annoView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:ID];
if (annoView == nil) {
annoView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:ID];
// 显示气泡
annoView.canShowCallout = YES;
// 设置绿色
annoView.pinColor = MKPinAnnotationColorGreen;
}
return annoView;
}
// 定位管理器
_mgr = [[CLLocationManager alloc] init];
// 获取授权
[_mgr requestAlwaysAuthorization];
// 设置代理
_mgr.delegate = self;
// 设置精度
_mgr.desiredAccuracy = kCLLocationAccuracyBest;
// 开始获取用户的位置
[_mgr startUpdatingLocation];
定位管理器的代理方法:
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations•
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
通过地址获得经纬度 :
CLGeocoder:地理信息编解码
_geocoder = [[CLGeocoder alloc] init];
[_geocoder geocodeAddressString:@“东三旗" completionHandler:^(NSArray *placemarks, NSError *error) {
//没有找到符合要求的地址
if (placemarks.count == 0) return;
// 取出位置
CLPlacemark *firstPlacemark = placemarks[0];
// 添加大头针
MyAnnotation *anno = [[MyAnnotation alloc] init];
anno.title = firstPlacemark.name; // 名称
anno.subtitle = firstPlacemark.country; // 国家
anno.coordinate = firstPlacemark.location.coordinate; // 坐标
[_mapView addAnnotation:anno];
}];
iOS:地图:MapKit和CoreLocation的更多相关文章
- [iOS 利用MapKit和CoreLocation框架打造精简的定位和导航]
运行效果: 一.利用<CoreLocation/CoreLocation.h>定位 创建变量 CLLocationManager *locationManager , ...
- iOS地图----MapKit框架
1.MapKit框架使用前提 ①导入框架 ②导入主头文件 #import <MapKit/MapKit.h> ③MapKit框架使用须知 MapKit框架中所有数据类型的前缀都是MK Ma ...
- IOS之【地图MapKit】
iOS地图位置开发 iPhone SDK提供了三个类来管理位置信息:CLLocation CLLocationManager 和 CLLHeading(不常用).除了使用GPS来获取当前的位置信息 ...
- 【高德API】如何利用MapKit开发全英文检索的iOS地图
原文:[高德API]如何利用MapKit开发全英文检索的iOS地图 制作全英文地图的展示并不困难,但是要制作全英文的数据检索列表,全英文的信息窗口,你就没办法了吧.告诉你,我有妙招!使用iOS自带的M ...
- iOS- 用MapKit和CoreLocation 来实现移动设备(地图与定位)
1.前言 发现在很多的社交软件都引入了地图和定位功能,如果我们要想实现这两大功能,需要利用到两个框架:MapKit和CoreLocation 我们先来看看CoreLocation框架: 它可以 ...
- iOS学习笔记-地图MapKit入门
代码地址如下:http://www.demodashi.com/demo/11682.html 这篇文章还是翻译自raywenderlich,用Objective-C改写了代码.没有逐字翻译,如有错漏 ...
- iOS开发拓展篇—CoreLocation简单介绍
iOS开发拓展篇—CoreLocation简单介绍 一.简介 1.在移动互联网时代,移动app能解决用户的很多生活琐事,比如 (1)导航:去任意陌生的地方 (2)周边:找餐馆.找酒店.找银行.找电影院 ...
- iOS开发拓展篇—CoreLocation地理编码
iOS开发拓展篇—CoreLocation地理编码 一.简单说明 CLGeocoder:地理编码器,其中Geo是地理的英文单词Geography的简写. 1.使用CLGeocoder可以完成“地理编码 ...
- 【iOS地图开发】巧妙打造中英文全球地图
地图开发的同学们经常遇到这样的问题,国内版地图开发,用高德或者百度就行了.但是,国外的地图怎么办?这里告诉大家,如果利用iOS地图,打造中英文的,国内国外都能用的,全球地图. 制作全英文地图的展示并不 ...
随机推荐
- 仿照CREATE_FUNC实现CCLayer中的返回CCScene* 的静态函数,宏包装成CREATE_SCENE(XXLayer)
#define CREATE_SCENE(__TYPE__)\ CCScene *scene()\ { CCScene *scene=CCScene::create();\ __TYPE__ *lay ...
- pspo
一.项目计划总结: 周活动总结表 姓名: 日期:3.12.2015 日期 任务 听课 编写程序 阅读课本 准备考试 日总计 周日 周一 周二 周三 10:00- ...
- 【转载】openldap 备份与导入 及相关问题--扩展
http://www.cnblogs.com/ccdc/p/3356518.html 摘要: 对openldap进行备份时,直接使用slapcat命令进行备份,使用ldapadd还原出现问题及解决. ...
- 创建ubuntu软件源
缘起:虚拟机需要安装一些文件,但是直接从外网下载比较慢,而且安装iso包中是有这些软件的,所以创建一个ubuntu apt server ubuntu 12.04, 本机192.168.0.124, ...
- 【Binary Tree Post order Traversal】cpp
题目: Given a binary tree, return the postorder traversal of its nodes' values. For example:Given bina ...
- Function模式 -- 深入理解javascript
/* 一.回调函数 函数A作为另外一个函数B的参数 */ var menuId = $("ul.nav").first().attr("id"); var re ...
- Nagios全方位告警接入-电话/微信/短信都支持
百度告警平台地址: http://gaojing.baidu.com 联系我们: 邮箱:gaojing@baidu.com 电话:13924600771 QQ群:183806029 Nagios接入 ...
- MYbatis调试日记(三)
如何在Mybatis中插入日期类型的数据 直接见代码: xml配置文件 java代码
- Ionic 安装部署
Ionic 安装部署 准备工作 下载安装Node.js, JDK,Apache Ant,Android SDK:编辑器用WebStorm node jdk ant 均需要加进 环境变量path中 An ...
- 连接ACCESS 数据库不能使用 '';文件已在使用中。
错误类型: Microsoft JET Database Engine (0x80004005) 不能使用 '':文件已在使用中. 对数据库的操作完之后,要 conn.close() 错误原因:解 ...