- 浏览: 1312092 次
- 性别:
- 来自: 成都
文章分类
- 全部博客 (471)
- 原创文章 (4)
- Database (84)
- J2SE (63)
- Web (26)
- Javascript (30)
- Lucene (11)
- os (13)
- 算法 (8)
- Webservice (1)
- Open projects (18)
- Hibernate (18)
- Spring (15)
- Css (2)
- J2ee (2)
- 综合技术 (18)
- 安全管理 (13)
- PatternsInJava (27)
- NIO (5)
- Ibatis (2)
- 书籍收藏 (1)
- quartz (7)
- 并发编程 (15)
- oracle问题 (2)
- ios (60)
- coco2d-iphone (3)
- C++ (6)
- Zookeeper (2)
- golang (4)
- animation (2)
- android (1)
最新评论
-
dandingge123:
【引用】限制UITextField输入长度的方法 -
qja:
...
对List顺序,逆序,随机排列实例代码 -
安静听歌:
现在在搞这个,,,,,哎~头都大了,,,又freemarker ...
通用大型网站页面静态化解决方案(一) -
springdata-jpa:
java quartz定时任务demo教程源代码下载,地址:h ...
Quartz 配置参考 -
马清天:
[b][/b][list][*]引用[u][/u][/list ...
通用大型网站页面静态化解决方案(一)
Leonbao:MapKit学习笔记
1、概述
插入MapView,设置Delegate(一般为Controller),Annotations记录兴趣位置点(AnnotationView用来显示兴趣位置点),annotation是可选的,选中的annotation会显示callout,用来显示信息。
2、设置地图显示类型:
mapView.mapType = MKMapTypeStandard;
mapView.mapType = MKMapTypeSatellite;
mapView.mapType = MKMapTypeHybrid;
3、显示用户位置
设置为可以显示用户位置:
mapView.showsUserLocation = YES;
判断用户当前位置是否可见(只读属性):
userLocationVisible
得到用户位置坐标:当userLocationVisible为YES时
CLLocationCoordinate2D coords = mapView.userLocation.location.coordinate;
4、坐标范围
MKCoordinateRegion用来设置坐标显示范围。
包括两部分:Center(CLLocationCoordinate2D struct,包括latitude和longitude),坐标中心
和Span(MKCoordinateSpan struct,包括latitudeDelta和longitudeDelta),缩放级别
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(center,2000, 2000);
以上代码创建一个以center为中心,上下各1000米,左右各1000米得区域,但其是一个矩形,不符合MapView的横纵比例
MKCoordinateRegion adjustedRegion = [mapView regionThatFits:viewRegion];
以上代码创建出来一个符合MapView横纵比例的区域
[mapView setRegion:adjustedRegion animated:YES];
以上代码为:最终显示该区域
5、Delegate
使用MapView须符合MKMapViewDelegate协议
5.1、地图加载Delegate
当需要从Google服务器取得新地图时
mapViewWillStartLoadingMap:
当成功地取得地图后
mapViewDidFinishLoadingMap:
当取得地图失败后(建议至少要实现此方法)
mapViewDidFailLoadingMap:withError:
5.2、范围变化Delegate
当手势开始(拖拽,放大,缩小,双击)
mapView:regionWillChangeAnimated:
当手势结束(拖拽,放大,缩小,双击)
mapView:regionDidChangeAnimated:
判断坐标是否在MapView显示范围内:
CLLocationDegrees leftDegrees = mapView.region.center.longitude –(mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees rightDegrees = mapView.region.center.longitude +(mapView.region.span.longitudeDelta / 2.0);
CLLocationDegrees bottomDegrees = mapView.region.center.latitude –(mapView.region.span.latitudeDelta / 2.0);
CLLocationDegrees topDegrees = self.region.center.latitude +(mapView.region.span.latitudeDelta / 2.0);
if (leftDegrees > rightDegrees) { // Int’l Date Line in View
leftDegrees = -180.0 – leftDegrees;
if (coords.longitude > 0) // coords to West of Date Line
coords.longitude = -180.0 – coords.longitude;
}
If (leftDegrees <= coords.longitude && coords.longitude <=
rightDegrees && bottomDegrees <= coords.latitude &&
coords.latitude <= topDegrees) {
// 坐标在范围内
}6、Annotation
Annotation包含两部分:Annotation Object和Annotation View
Annotation
Object必须符合协议MKAnnotation,包括两个方法:title和subtitle,分别用于显示注释的标题和子标题。还有
coordinate属性,返回CLLocationCoordinate2D,表示Annotation的位置
然后,需使用mapView:viewForAnnotation: 方法来返回MKAnnotationView或者MKAnnotationView的子类用来显示Annotation(注意:这里显示的不是选中Annotation后的弹出框)
你可以子类化MKAnnotationView,然后再drawRect:方法里面进行自己的绘制动作(这个方法很蠢)
你完全可以实例化一个MKAnnotationView,然后更改它的image属性,这样很简单。
7、添加移除Annotation
添加一个Annotation
[mapView addAnnotation:annotation];
添加一个Annotation数组
[mapView addAnnotations:[NSArray arrayWithObjects:annotation1, annotation2, nil]];
移除一个Annotation
removeAnnotation:
移除一个Annotation数组
removeAnnotations:
移除所有Annotation
[mapView removeAnnotations:mapView.annotations];
8、选中Annotation
一次只能有一个Annotation被选中,选中后会出现CallOut(浮动框)
简单的CallOut显示Title和SubTitle,但你也可以自定义一个UIView作为CallOut(与自定义的TableViewCell一样)
可通过代码选中Annotation:
selectAnnotation:animated:
或者取消选择:
deselectAnnotation:animated:
9、显示Annotation
通过mapView:viewForAnnotation: 方法显示Annotation,每在MapView中加入一个Annotation,就会调用此方法
示例(与tableView:cellForRowAtIndexPath: 很相似)
- (MKAnnotationView *) mapView:(MKMapView *)theMapView viewForAnnotation:(id <MKAnnotation>) annotation {
static NSString *placemarkIdentifier = @”my annotation identifier”;
if ([annotation isKindOfClass:[MyAnnotation class]]) {
MKAnnotationView *annotationView = [theMapView dequeueReusableAnnotationViewWithIdentifier:placemarkIdentifier];
if (annotationView == nil) {
annotationView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:placemarkIdentifier];
annotationView.image = [UIImage imageNamed:@"blood_orange.png"];
}
else
annotationView.annotation = annotation;
return annotationView;
}
return nil;
}10、取得真实地址
示例:
初始化MKReverseGeocoder
MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:coordinates];
geocoder.delegate = self;
[geocoder start];
如果无法处理坐标,则调用reverseGeocoder:didFailWithError: 方法
- (void)reverseGeocoder:(MKReverseGeocoder *)geocoder didFailWithError:(NSError *)error {
NSLog(@”Error resolving coordinates: %@”, [error localizedDescription]);
geocoder.delegate = nil;
[geocoder autorelease];
}
如果成功,则调用reverseGeocoder:didFindPlacemark: 并把信息存储在MKPlacemark 中
didFindPlacemark:(MKPlacemark *)placemark {
NSString *streetAddress = placemark.thoroughfare;
NSString *city = placemark.locality;
NSString *state = placemark.administrativeArea;
NSString *zip = placemark.postalCode;
// Do something with information
geocoder.delegate = nil;
[geocoder autorelease];
}
发表评论
-
ios 声音合成
2013-08-18 13:20 1226http://stackoverflow.com/ques ... -
__bridge,__bridge_retained和__bridge_transfer的意思,区别与使用 20 三
2012-12-24 01:41 1627使用ARC能帮我们减轻不少内存管理方面的负担,尤其是对用 ... -
CAAnimation
2012-12-23 01:09 2295CAAnimation采用了CAMediaTi ... -
UIViewAnimation动画与Core Animation的CATransition类动画
2012-12-23 01:06 2688使用UIView类函数实现://U ... -
GCD实战2:资源竞争
2012-12-23 01:04 1547转自http://www.dreamingwish.co ... -
GCD实战一:使用串行队列实现简单的预加载
2012-12-22 17:10 2809转自 http://www.dreamingwish.c ... -
GCD介绍(四): 完结
2012-12-22 17:08 1318转自 http://www.dreamingwish.c ... -
GCD介绍(三): Dispatch Sources
2012-12-22 17:07 1591转自 http://www.dreamingwish.com/ ... -
GCD介绍(二): 多核心的性能
2012-12-22 17:05 1142转自http://www.dreamingwish.co ... -
基本概念和Dispatch Queue
2012-12-22 17:03 1306转自 http://www.dreamingwish.c ... -
Best Audio Format for iPhone Audio Programming
2012-12-19 16:26 2495I had never done audio p ... -
LAME 是一个开源的MP3解码编码工具
2012-12-19 13:09 8490MP3 Encoding * 编码MP3文件必须按如下 ... -
sqlite3中的数据类型
2012-12-10 21:37 1252(转)http://www.cnblogs.com/kfqco ... -
ios随机数,and()、random()、arc4random()
2012-11-15 11:06 4684原文:http://bj007.blog.51cto.c ... -
IPHONE GIF 播放的方式
2012-10-11 18:30 1412转 http://blog.csdn.net/zltia ... -
在新线程中使用NSTimer
2012-10-11 18:21 1547转自 http://blog.csdn.net/sjzs ... -
Creating an iPhone Daemon – Part 5
2012-09-02 15:29 1504Creating an iPhone Daemon – ... -
Creating an iPhone Daemon – Part 4
2012-09-02 15:28 1374Creating an iPhone Daemon – ... -
Creating an iPhone Daemon – Part 3
2012-09-02 15:25 1472This is part three of the bl ... -
Creating an iPhone Daemon – Part 2
2012-09-02 15:24 1216Here is part two of the blog ...
相关推荐
ios-guided-project-mapkit-starter:MapKit入门指南项目
不再受支持。 在针对WWDC18公开之前,它使用了未记录的MapKit JS功能。 mapkit-js-demo 在查看。
使用地图 在地图上显示目标区域 步骤 0. 添加“MKMapViewDelegate”协议 class ViewController: UIViewController, MKMapViewDelegate {...} 步骤 1.... // Step1.... // - 1.1 Define position var latitude:...
我在哪里 将位置转换为美国地址格式 func locationManager(manager: CLLocationManager!, didUpdateLocations locations: [AnyObject]!) { var usrLocation:CLLocation = locations[0] as CLLocation ...
Xcode4开发基础教程,ios5 Chapter 1: Before We Get Started Chapter 2: Blast-Off!...Chapter 10: MapKit & Tables with Storyboarding Chapter 11: Storyboarding to Multimedia Platforms Index
plugman install --platform android --project android-mapkit-example/ --plugin /path/to/MapKit --variable API_KEY="YOUR_API_KEY_FROM_GOOGLE" 或使用cordova CLI cordova -d plugin add /path/to/MapKit -...
mapKit
Apple Mapkit JS演示应用程序 这是一个节点js应用程序,使用Mapkit JS在浏览器中演示了Apple的Map。 要求 您需要Node js版本6或更高版本 通过此创建和下载Apple Maps的私钥 入门 cp .env-sample .env 在.env文件中...
MapKit MapKit是一个iOS“库”,用于显示平铺的地图。 虽然MKMapView是在iOS 3.0中引入的,但除了Google Maps之外,它不支持图块提供程序。 尽管这对于大多数人来说不是一个大问题,但它阻止开发人员构建使用来自非...
Chapter 1: Before We Get Started Chapter 2: Blast-Off! Chapter 3: What’s Next? Chapter 4: An Introduction to the Code Chapter 5: Buttons & Labels with Multiple Graphics ...Chapter 9: MapKit
SHPonMapKit 在MapKit上绘制形状文件多边形加载形状文件并使用drawMapRect在MapKit上绘制图形的简单快捷的测试。 使用shapelib的普通项目,视频在这里: 到目前为止仅绘制多边形基本优化,无规模优化shapefile中的...
MKG测地线-Polyline-Swift 在Swift编写的MapKit中沿弧线对元素进行动画处理
iOS-Zip3-Mapkit iOS动态zip3热图库的概念证明。 这利用了: #PA Zip3示例大致基于PA的Zip3代码示例数据集。
IOS MapKit应用
MapKit 位置 推送 分析 ScanKit Dtm Api 该地图示例使用了自定义的集群代码,该代码也已构建并绑定到Xamarin。 原始项目可以在这里找到: : 。 运行样本 为了运行该示例,您将需要具有Huawei Developer帐户。...
unity-mapkit Unity 的 Mapkit 灯光包装器
mapkit地图定位,自己编辑当前的位置
MapKit:用于了解有关MapKit的更多信息的简单项目
GEOSwiftMapKit 有关完整详细信息,请参阅 要求 iOS 9.0+, tvOS 9.2+, macOS 10.9+ (CocoaPods, Carthage, Swift PM) 斯威夫特 5.1 GEOS 在 LGPL 2.1 下获得许可,它与静态链接的兼容性至少是有争议的。...
地图位置更新器这将更新位置并返回地址,类似于拼车应用。 优步、Lyft 和 SideCar截图: