第四篇 iOS MKMapView的总结
来源:互联网 发布:淘宝被店家限制购买 编辑:程序博客网 时间:2024/05/29 05:10
首先初始化
_rootMapView = [[MKMapView alloc]initWithFrame:CGRectMake(x,x,x,x)];
_rootMapView.delegate = self;
_rootMapView.mapType = MKMapTypeStandard;
_rootMapView.showsUserLocation = YES; //设置定位
定位
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{
mapView.showsUserLocation = NO;
my = MKMapPointForCoordinate(userLocation.location.coordinate);
_rootMapView.region = MKCoordinateRegionMakeWithDistance(userLocation.location.coordinate, 10000, 10000);// 设置显示的跨度
}
当地图的显示范围发生变化的方法
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{
double meter = MKMapPointsPerMeterAtLatitude(mapView.centerCoordinate.latitude);//每个像素的跨度是多少米
}
在地图添加MKPointAnnotation
for (int i = 0; i<[_annArray count]; i++) {
PointAnnotation *ann = [[[PointAnnotation alloc]initWithDiction:[_annArray objectAtIndex:i]]autorelease];
[arrayPoint addObject:ann];
[_rootMapView addAnnotation:ann];
}
//继承MKPointAnnotation的PointAnnotation
//
//@interface PointAnnotation : MKPointAnnotation
//
//@property (nonatomic, copy) NSString *title;
//@property (nonatomic, copy) NSString *subtitle;
//@property (nonatomic, assign) NSString *locationType;
//@property (nonatomic, retain) NSString *userName;
//
//@property (nonatomic, retain) NSString *header;
//
//- (id)initWithLocation:(CLLocationCoordinate2D)coord userName:(NSString *)newUser headerUrl:(NSString *)url;
//-(id)initWithDiction:(NSDictionary *)dic;
//
//@implementation PointAnnotation
//@synthesize title,subtitle,locationType,userName,header;
//
//- (id)initWithLocation:(CLLocationCoordinate2D)coord userName:(NSString *)newUser headerUrl:(NSString *)url{
// self = [super init];
// if (self) {
// self.coordinate = coord;
// userName = newUser;
// header = url;
// }
// return self;
//}
//-(id)initWithDiction:(NSDictionary *)dic{
// NSString *str = [dic objectForKey:@"Location"];
// NSRange range = [str rangeOfString:@","];
// NSString *first = [str substringToIndex:range.location];
// NSString *secend = [str substringFromIndex:range.location+1];
// double f = [first doubleValue];
// double s = [secend doubleValue];
// MKMapPoint point = {f,s};
// self.coordinate = MKCoordinateForMapPoint(point);
// userName = [dic objectForKey:@"Name"];
// header = [dic objectForKey:@"HeadUrl"];
// return self;
//}
设置自定义大头针的View
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
if ([annotation isKindOfClass:[PointAnnotation class]]){
PointAnnotation *anno = (PointAnnotation *)annotation;
//CustomAnnotationView 继承 MKAnnotationView;
CustomAnnotationView *pinView = [[[CustomAnnotationView alloc]initWithAnnotation:anno reuseIdentifier:@"PointAnnotation"]autorelease];
pinView.annotation = annotation;
[pinView createView];
pinView.canShowCallout = NO;//是否有callout View
return pinView;
}
return nil;
}
点击AnnotationView的事件
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view {
}
- 第四篇 iOS MKMapView的总结
- iOS 苹果地图 MKMapView总结
- iOS开发--MKMapView的使用
- ios MKMapView的简单使用
- iOS MKMapView
- iOS-MKMapView
- ios利用MKMapView实现简单的地图
- ios利用MKMapView实现简单的地图
- iOS 设置MKMapView的缩放级别
- iOS开发 地图:MKMapView控件的使用
- MKMapView iOS的地图详细应用
- IOS MKMapView 基础
- iOS地图MKMapView详析
- iOS开发之-MKMapView
- IOS MKMapView 地图视图
- iOS MKMapView嵌入地图
- IOS MKMapView 地图视图
- iOS开发--MKMapView截图
- Java调用C++
- 关于在ScrollView中嵌套ListView,ListView显示不全的问题
- Failed to fetch URL http://dl.htcdev.com/sdk/addon.xml, reason: peer not authenticated
- android HID添加(四) ---INTERNET KEY
- 女孩不是拜金,是败给了生活
- 第四篇 iOS MKMapView的总结
- Lua中用Split函数分割字符串
- Hive内置数据类型
- NGUI基本控件使用
- 第9章 WLAN基础
- ArcGIS线性参考及动态分段在交通中的应用【一】
- 网购狂欢节背后的技术阅兵(保存地址)
- VS2010 MFC exe独立系统环境运行
- 22种实用的心理调节法