IOS 在MkMapView中添加自己当前位置的大头针的方法
2016-09-08 14:14
393 查看
在利用MKMapView显示自己当前位置的地图一文中介绍了放大地图和显示自己的位置,下面介绍一下在地图自己位置上添加大头针,实现如下所示:
实现的具体过程很简单:
首先实现MKMapViewDelegate协议:
@interface iphone_MapViewController : UIViewController
{
IBOutlet MKMapView *mapView;
}
然后添加代码:
- (void)viewDidLoad {
[super viewDidLoad];
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];
}
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
{
MKPinAnnotationView *pinView = nil;
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;
[mapView.userLocation setTitle:@"欧陆经典"];
[mapView.userLocation setSubtitle:@"vsp"];
return pinView;
}
实现的具体过程很简单:
首先实现MKMapViewDelegate协议:
@interface iphone_MapViewController : UIViewController
{
IBOutlet MKMapView *mapView;
}
然后添加代码:
- (void)viewDidLoad {
[super viewDidLoad];
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];
}
- (MKAnnotationView *)mapView:(MKMapView *)mV viewForAnnotation:(id )annotation
{
MKPinAnnotationView *pinView = nil;
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;
[mapView.userLocation setTitle:@"欧陆经典"];
[mapView.userLocation setSubtitle:@"vsp"];
return pinView;
}
相关文章推荐
- 在MkMapView中添加自己当前位置的大头针的方法
- 在MkMapView中添加自己当前位置的大头针
- 利用MKMapView显示自己当前位置的地图
- ios-MKMapView上添加大头针
- 利用MKMapView显示自己当前位置的地图
- iOS drawRect方法中在超过当前view边界的位置绘图
- IOS应用开发中的tips - MKMapView之设置地图以用户当前位置为中心
- 在MkMapView中在指定位置添加大头针
- 在MkMapView中在指定位置添加大头针
- 【iOS开发-110】MapKit框架的主要类MKMapView以及代理方法,大头针的使用addAnnotation
- [IOS地图开发系类]4、MKMapview上添加MKAnnotationView,标记当前位置
- iPhone开发之在MkMapView中在指定位置添加大头针
- GoogleMap_IOS MKMapView如何实现不点击大头针,就可以出现calloutView效果
- iOS开发--MKMapView添加UIPanGestureRecognizer
- iOS 输入地点 显示当前位置地图并用大头针标注
- 如何定位到append的当前位置,不用拉滚动条scrollIntoView方法
- iOS:对View添加动画的常用方法
- ios UIImageView添加图片动画效果,添加了手势之后,依然没有反应的解决方法