iOS 地图制作讲义
来源:互联网 发布:广东省发票打印软件 编辑:程序博客网 时间:2024/06/07 07:09
一.系统原生地图
1.什么是LBS
LBS:基于位置的服务 Location Based Service
实际应用:大众点评,陌陌,微信,百度地图
2.定位原理
1.GPS定位 2.基站定位 3.WIFI定位
3.定位使用框架
MapKit:显示地图
CoreLocation:定位框架,没有地图时也可以定位.
4.如何使用系统地图
1).初始化MapView
_mapView = [[MKMapViewalloc]initWithFrame:self.view.bounds];
[self.viewaddSubview:_mapView];
2).设置地图中心坐标点
CLLocationCoordinate2D cl2d =CLLocationCoordinate2DMake(22.540396,113.951832);
_mapView.centerCoordinate = cl2d;
3)设置地图显示区域
MKCoordinateSpan span =MKCoordinateSpanMake(0.01,0.01);
MKCoordinateRegion region =MKCoordinateRegionMake(cl2d, span);
_mapView.region = region;
4).设置地地图类型
_mapView.mapType =MKMapTypeStandard;
5).允许显示自己的位置
_mapView.showsUserLocation =YES;
6).初始化定位管理器
_manager = [[CLLocationManageralloc]init];
_manager.delegate =self;
7).ios8如何定位
1.在info.plist中添加 Privacy - Location Usage Description , NSLocationAlwaysUsageDescription
2.在代码中 [_manager requestAlwaysAuthorization];
8).定位成功代理
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
9).定位失败代理
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
10).自定义大头针
- (CLLocationCoordinate2D)coordinate;
- (NSString *)title;
- (NSString *)subtitle;
- (id)initWithCoordinate:(CLLocationCoordinate2D )cl2d andTitle:(NSString *)title andSubTitle:(NSString *)subTitle;
- (id)initWithCoordinate:(CLLocationCoordinate2D)cl2d andTitle:(NSString *)title andSubTitle:(NSString *)subTitle
{
if (self = [superinit]) {
_cl2d = cl2d;
_title = title;
_subTitle = subTitle;
}
returnself;
}
11).大头针的复用及定制
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>)annotation
{
staticNSString *reused =@"reused";
MKPinAnnotationView *pin = (MKPinAnnotationView *)[mapViewdequeueReusableAnnotationViewWithIdentifier:reused];
if (pin ==nil) {
pin = [[MKPinAnnotationViewalloc]initWithAnnotation:annotationreuseIdentifier:reused];
pin.canShowCallout =YES;
pin.pinColor =MKPinAnnotationColorGreen;
pin.animatesDrop =YES;
UIView *v = [[UIViewalloc]initWithFrame:CGRectMake(0,0,35, 35)];
v.backgroundColor = [UIColorredColor];
pin.leftCalloutAccessoryView = v;
UIButton *b = [UIButtonbuttonWithType:UIButtonTypeSystem];
b.frame =CGRectMake(0,0,35, 35);
[b setTitle:@"按钮"forState:UIControlStateNormal];
pin.rightCalloutAccessoryView = b;
}
return pin;
}
12).屏幕坐标转经纬度坐标
CLLocationCoordinate2D cl2d = [_mapViewconvertPoint:pointtoCoordinateFromView:_mapView];
13).反地理编码
CLLocation *location = [[CLLocationalloc]initWithLatitude:cl2d.latitudelongitude:cl2d.longitude];
CLGeocoder *geocoder = [[CLGeocoderalloc]init];
[geocoder reverseGeocodeLocation:locationcompletionHandler:^(NSArray *placemarks,NSError *error) {
CLPlacemark *mark = [placemarks lastObject];
myPin *pin = [[myPinalloc]initWithCoordinate:cl2dandTitle:mark.countryandSubTitle:mark.name];
[_mapViewaddAnnotation:pin];
}];
14).移除大头针
[_mapViewremoveAnnotations:_mapView.annotations];
二.高德地图的使用
http://lbs.amap.com
根据文档实现
1:地图的显示
2:POI 搜索
- iOS 地图制作讲义
- 讲义
- 讲义
- 讲义
- IOS 地图
- ios地图
- iOS 地图
- iOS 地图
- iOS地图
- 二维地图的制作
- 如何制作网站地图
- iPhone4离线地图制作
- Tile地图制作
- unity3d简单地图制作
- 百度地图的制作
- 网站地图制作
- 地图的制作
- 离线地图制作
- 3.安装和配置ibati
- 怎样在Win7系统建立并开启Wifi热点
- php 等比例生成缩略图
- 去除String 小数点后多余的0
- UltraEdit编辑器如何查看项目中某个变量,方法出现在那些地方使用了
- iOS 地图制作讲义
- Excel 2010 VBA实战技巧精粹——互动出版网
- ZOJ - 3611——Ice Valley
- 跑马灯效果
- Myeclipse下Web环境配置
- 单例模式的优缺点
- 百度翻译api 网页应用
- COLORREF 和RGBQUAD的区别
- RMQ 之 ST算法的使用 【总结】 【附带求固定区间长度的一维技巧】