- 浏览: 233552 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
lanzhiyuan:
楼主还混这里不?NSData *data = [NSURLCo ...
[转] 为UIWebView实现离线浏览 -
hyc4117:
#define OpenSSLRSAPublicKeyFile ...
IOS openssl rsa encrypt/decrypt -
guogongjun:
确实有效,不错,感谢啦大神
[转]安装openfire后admin无法登录管理控制平台 -
xiongyoudou1:
怎么办,而且你那下载的demo和你讲解的不是一样
[转] 为UIWebView实现离线浏览 -
xiongyoudou1:
有问题。执行到方法NSData *data = [NSURLC ...
[转] 为UIWebView实现离线浏览
在MKMapView中加pin其实就是加入MKAnnonation, 可以加入服和MKAnnonation协议的pin,下面展示一下方法。
1.首先创建一个服和MKAnnonation协议的委托类
2. 实例化该委托对像,加入到MKMapView中。
另一处介绍
修改viewDidLoad方法
注意:无论是自定义的MKAnnotationView还是标准的,一旦addAnnotation to MapView,如何更新它在地图上的位置呢?更新MKAnnotation protocol中的coordinate可以做到吗? 如果是手动更新位置是不可以让它在地图上移动的。请看官网文档 ,其中有一段描述:
手动更新后必须用KVO的方式通知系统,不然系统是不知道更新位置的。如何通知道呢,其实NSObject中有这样的方法willChangeValueForKey and didChangeValueForKey。如你写了个方法更新pin位置,如下:
IOS4中更新更简单,只需要调用- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;这个方法就可以自动更新了。
1.首先创建一个服和MKAnnonation协议的委托类
@interface AnnotationDelegate : NSObject <MKAnnotation> { CLLocationCoordinate2D coordinate; } @property (nonatomic, readonly) CLLocationCoordinate2D coordinate; - (id) initWithCoordinate:(CLLocationCoordinate2D)coord; @end @implementation AnnotationDelegate @synthesize coordinate; - (id) initWithCoordinate:(CLLocationCoordinate2D)coord { coordinate.latitude = coord.latitude; coordinate.longitude = coord.longitude; return self; } @end
2. 实例化该委托对像,加入到MKMapView中。
view plaincopy to clipboardprint? AnnotationDelegate * annotationDelegate = [[[AnnotationDelegate alloc] initWithCoordinate:coordinate] autorelease]; [self._mapView addAnnotation:annotationDelegate];
另一处介绍
#import <Foundation/Foundation.h> #import <MapKit/MKAnnotation.h> @interface DisplayMap : NSObject <MKAnnotation>{ CLLocationCoordinate2D coordinate; NSString *title; NSString *subtitle; } @property (nonatomic, assign) CLLocationCoordinate2D coordinate; @property (nonatomic, copy) NSString *title; @property (nonatomic, copy) NSString *subtitle; @end #import "DisplayMap.h" @implementation DisplayMap @synthesize coordinate,title,subtitle; -(void)dealloc{ [title release]; [super dealloc]; } @end
修改viewDidLoad方法
- (void)viewDidLoad { [super viewDidLoad]; //mapView.showsUserLocation=YES; self.mapView.delegate=self; CLLocationManager *locationManager = [[CLLocationManager alloc] init];//创建位置管理器 locationManager.delegate=self;//设置代理 locationManager.desiredAccuracy=kCLLocationAccuracyBest;//指定需要的精度级别 locationManager.distanceFilter=1000.0f;//设置距离筛选器 [locationManager startUpdatingLocation];//启动位置管理器 MKCoordinateRegion theRegion = { {0.0, 0.0 }, { 0.0, 0.0 } }; theRegion.center=[[locationManager location] coordinate]; [locationManager release]; [mapView setZoomEnabled:YES]; [mapView setScrollEnabled:YES]; theRegion.span.longitudeDelta = 0.01f; theRegion.span.latitudeDelta = 0.01f; [mapView setRegion:theRegion animated:YES]; DisplayMap *ann = [[DisplayMap alloc] init]; ann.title = @"欧陆经典"; ann.subtitle = @"vsp"; //地点名字 ann.coordinate = theRegion.center; [mapView addAnnotation:ann]; } - (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id <MKAnnotation>)annotation { MKPinAnnotationView *pinView = nil; if(annotation != mapView.userLocation) { static NSString *defaultPinID = @"com.invasivecode.pin"; pinView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:defaultPinID]; if ( pinView == nil ) pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID] autorelease]; pinView.pinColor = MKPinAnnotationColorRed; pinView.canShowCallout = YES; pinView.animatesDrop = YES; } else { [mapView.userLocation setTitle:@"欧陆经典"]; [mapView.userLocation setSubtitle:@"vsp"]; } return pinView; }
注意:无论是自定义的MKAnnotationView还是标准的,一旦addAnnotation to MapView,如何更新它在地图上的位置呢?更新MKAnnotation protocol中的coordinate可以做到吗? 如果是手动更新位置是不可以让它在地图上移动的。请看官网文档 ,其中有一段描述:
“Important: When you implement the coordinate property in your class, it is recommended that you synthesize its creation. If you choose to implement the methods for this property yourself, or if you manually modify the variable underlying that property in other parts of your class after the annotation has been added to the map, be sure to send out key-value observing (KVO) notifications when you do. Map Kit uses KVO notifications to detect changes to the coordinate, title, and subtitle properties of your annotations and make any needed changes to the map display. If you do not send out KVO notifications, the position of your annotations may not be updated properly on the map.For more information about how to implement KVO-compliant accessor methods, see Key-Value Observing Programming Guide.” |
手动更新后必须用KVO的方式通知系统,不然系统是不知道更新位置的。如何通知道呢,其实NSObject中有这样的方法willChangeValueForKey and didChangeValueForKey。如你写了个方法更新pin位置,如下:
view sourceprint?-(void)UpdateCoord:(CLLocationCoordinate2D)newCoord { [self willChangeValueForKey:@"coordinate"]; coordinate = newCoord; [self didChangeValueForKey:@"coordinate"]; }
IOS4中更新更简单,只需要调用- (void)setCoordinate:(CLLocationCoordinate2D)newCoordinate;这个方法就可以自动更新了。
- BigHeadTip.zip (938.1 KB)
- 下载次数: 30
发表评论
-
ios 开发技术
2015-01-09 11:59 689引用 主题:xcode 6制作动态&静态库 连接:ht ... -
ios 错误合集(updated!)
2015-01-09 11:57 760引用 错误:dyld: Library not loaded ... -
几个不错的xcode插件
2014-09-11 13:33 62471、代码补全插件 http://alcatraz.io 2、 ... -
xcode 插件目录
2014-09-11 13:14 417~/Library/Application\ Suppor ... -
GCD 倒计时
2014-08-19 10:00 960-(void)startTime{ __bloc ... -
Eventkit使用案例
2014-02-15 16:06 3149- (void)createNewEventAndNewR ... -
ios 应用内跳转到系统设置界面的最好写法
2013-04-24 11:43 10112如下是跳转到系统设置诸多界面的url prefs:roo ... -
beeframework "___gxx_personality_sj0", referenced from:错误解决
2013-04-17 13:50 1777到Bee_Precompile.h 找到如下一行: #de ... -
pod update/install git pull 443错误解决
2013-01-22 18:38 2283自从12306.cn抢票插件搞爆github服务器以后,我就再 ... -
[转]如何编写一个CocoaPods的spec文件
2012-12-27 16:25 14243本文转自http://ishalou.com/blog/201 ... -
[转]How to use NSAttributedString in iOS 6
2012-12-25 16:09 2512本文转自:http://soulwithmobiletechn ... -
mac上的小工具(updated)
2012-12-24 18:05 921mac上显示隐藏文件的命令,如果要隐藏则 -bool fals ... -
github README.md 编辑技巧小结 (updated)
2012-12-18 11:39 20181.文字连接 [文字](http://ace.ajax.org ... -
iOS 怎样更方便使用第三方框架
2012-11-29 12:45 1561管理第三方库越来越成为每个程序员的基本工作,因为每次都要去加入 ... -
CocoaPods:管理 Objective-C 專案裡頭各種 Library 關聯性最棒的方式
2012-11-26 14:53 1002介绍: 开发应用的时候第三方的库是不可缺少的,它能提高开发的 ... -
转载:用HTML5/CSS3/JS开发Android/IOS应用框架大全
2012-11-22 15:16 1204现在,用js调用本地代码已经不是一件新鲜事,已经有成熟的库来做 ... -
core data 分页查询
2012-11-07 11:26 1481NSFetchRequest *request = [[N ... -
[转]从Flurry导出数据
2012-10-17 10:51 1134有时我们需要一些详细 ... -
AFNetworking multipart upload
2012-10-12 14:52 5389+ (NSDictionary*)parametersOf ... -
IOS openssl rsa encrypt/decrypt
2012-09-29 15:15 6324对OpenSSL RSA加解密的封 ...
相关推荐
用更简单的方式去使用地图(支持 MapKit、高德地图、百度地图)
MapKit地图的使用技巧。
mapkit地图定位,自己编辑当前的位置
Swift 使用mapkit 实现在地图上两点(多点)画线,画多条·多种颜色的线 最终效果图: 首先新建一个项目(可选) 在storyboard中新建一个ViewController视图 然后新建一个UIViewController的之类并且在storyboard...
iOS5地图使用MapKit,使用CLGeocoder解析,原来的MKReverseGeocoder过时不可用
iOS 9 MapKit 地图 导航新增功能
学习demo 博文链接:https://justsee.iteye.com/blog/1770094
利用MapKit框架以及CLLocationManagerDelegate,MKMapViewDelegate协议实现地图定位
地图,大头针,定位编码反编码,苹果地图导航;
mapKit
在苹果自带地图上覆盖一层图片,图片可以随地图缩放移动,关键是自定义Overlay和OverlayView。
mapkit 上有时候会有很多annotation,如果全部照的原样显示出来未免有些杂乱,而且有的会重合。实例里根据zoom级别来自动调整显示的annotation,如果有重合的,用一个带有annotation计数的圆点图片来代替,这样简洁...
在苹果自带地图和百度地图上覆盖一层图片,图片可以随地图缩放移动。关键就是自定义Overlay和OverlayView。
IOS MapKit应用
GeoJSONSerialization, 在 GeoJSON & MapKit形状之间编码&解码 GeoJSONSerialization根据基础类的API约定,GeoJSONSerialization 在 GeoJSON 和 MapKit之间进行编码和解码。用法解码#import <MapKit/MapKit.h&
移动用户喜欢的功能之一是查看在地图表面上直接传达的信息。 当将天气,行车路线和客户位置叠加在地图上时,会更加详细地进行说明。 在本文中,我将逐步介绍使用Swift编程语言在MapKit地图上绘制MKPolyLine的步骤。...
ios纯代码实现.用CLLocation与mapkit实现定位与方位搜索的功能。若有不足之处欢迎大家评论指出~
IOS应用源码之Apple的MapKit相关官方Sample三个送上WeatherMap.zip