ios-地图-自定义大头针
来源:互联网 发布:苹果同步助手软件 编辑:程序博客网 时间:2024/05/17 01:49
#import "ViewController.h"//导入#import <MapKit/MapKit.h>#import "MyAnnotion.h"@interface ViewController ()<MKMapViewDelegate>//地图显示类@property (nonatomic, weak) MKMapView *mapView;@end@implementation ViewController- (MKMapView *)mapView{ if (!_mapView) { MKMapView *mapView = [[MKMapView alloc] initWithFrame:self.view.bounds]; [self.view addSubview:mapView]; CLLocationCoordinate2D coordinate2D = {39.9087607478,116.3975780499}; MKCoordinateSpan span = {.01,.01}; MKCoordinateRegion region = MKCoordinateRegionMake(coordinate2D, span); //设置范围 [mapView setRegion:region]; mapView.delegate = self; _mapView = mapView; } return _mapView;}- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //MKPointAnnotation; //id<MKAnnotation> //[self.mapView addAnnotation:(id<MKAnnotation>)]; //百度。高德。google CLLocationCoordinate2D coordinate2D = {39.9087607478,116.3975780499}; //添加标注 MyAnnotion *annotion = [[MyAnnotion alloc] initWithCoordinate2D:coordinate2D title:@"北京市" subtitle:@"天安门"]; [self.mapView addAnnotation:annotion]; CLLocationCoordinate2D coordinate2D2 = {39.9097607478,116.39875780499}; MyAnnotion *annotion2 = [[MyAnnotion alloc] initWithCoordinate2D:coordinate2D2 title:@"北京市" subtitle:@"天安门"]; [self.mapView addAnnotation:annotion2]; //计算两个经纬度之间的距离 //保存地理信息 CLLocation *l1 = [[CLLocation alloc] initWithLatitude:coordinate2D.latitude longitude:coordinate2D.longitude]; CLLocation *l2 = [[CLLocation alloc] initWithLatitude:coordinate2D2.latitude longitude:coordinate2D2.longitude]; //计算两个经纬度之间的距离(单位是米) CLLocationDistance distance = [l1 distanceFromLocation:l2]; NSLog(@"---%f",distance); }#pragma mark - MKMapViewDelegate/** * 添加标注的时候会触发(addAnnotation:) * * @param mapView <#mapView description#> * @param views <#views description#> */- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views{ NSLog(@"----%@",views);}/** * 返回大头针视图 * * @param mapView <#mapView description#> * @param annotation <#annotation description#> * * @return <#return value description#> */- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation{ //1.从复用队列里面通过标示符找可用的大头针对象 MKPinAnnotationView *pin = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:@"annotation"]; if (!pin) { //2.如果没有找到,就创建 pin = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"annotation"]; //显示气泡(三角视图) pin.canShowCallout = YES; /* MKPinAnnotationColorRed(默认) MKPinAnnotationColorGreen, MKPinAnnotationColorPurple */ //修改大头针颜色 pin.pinColor = MKPinAnnotationColorPurple; } return pin; }- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
0 0
- ios-地图-自定义大头针
- iOS 百度地图自定义大头针。
- ios 地图大头针自定义显示图片 MKAnnotationView
- ios 地图大头针自定义显示图…
- IOS百度地图自定义大头针和气泡
- iOS 自定义百度地图大头针点击事件
- IOS百度地图自定义大头针和气泡
- 百度地图自定义大头针
- ios 实现地图的定位,查询,自定义大头针
- iOS地图和定位服务(自定义大头针)
- iOS开发之百度地图大头针的自定义解决方法
- iOS百度地图自定义大头针和气泡内的内容
- iOS 百度地图_自定义Annotation大头针_修改大头针图片
- iOS 百度地图_自定义Annotation大头针_修改大头针图片
- iOS 大头针 MKAnnotationView 自定义
- 【iPhone Demo】地图自定义大头针
- 【iPhone Demo】地图自定义大头针
- 自定义:地图标注(大头针)
- 【DP】【Greedy】[CodeForces - 581E] Kojiro and Furrari
- mysql中的运算符和函数
- 单例模式
- ubuntu安装hadoop详细方法
- 通知
- ios-地图-自定义大头针
- ZIGBEE的组网和传输距离
- ubuntu下hadoop配置指南
- 构造函数和clone以及在继承中
- so sweet
- Math类的取整方法
- 递归调用实现命令行中以树状结构展现特定的文件夹及其子文件夹
- 测试基础学习心得
- QCustomPlot之性能提升