您的位置:首页 > 移动开发 > IOS开发

ios开发 地图上显示大头针和标注简单教程

2015-03-09 19:45 381 查看
1.首先导入框架 MapKit.framework和
CoreLocation.framework
2.再导入头文件
#impor
#impor
3.//创建MKMapView的实例

MKMapView
*mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0.0,0.0,
320.0,[UIScreen
mainScreen].bounds.size.height-20-44)];
[self.view
addSubview:mapView];

self.mapView = mapView;
[mapView
release];

//
为了干预annotationview的创建过程,设置mapview的delegate

self.mapView.delegate =
self;
4.//显示某个region

//
中心点坐标()self.latitude经度,self.longitude纬度,这是自己定义的float类型属性

self.latitude=31.43715199999999;
self.longitude=121.13612;

CLLocationCoordinate2D
coordinate =CLLocationCoordinate2DMake(self.latitude,
self.longitude);

//
显示尺寸span

MKCoordinateSpan
span = MKCoordinateSpanMake(0.04,0.04);

self.mapView.region =
MKCoordinateRegionMake(coordinate,span);
以上步骤已经可以显示一个地图(高德),下面是显示大头针形式的标注
创建一个timer让它1.5秒后显示出来

[NSTimerscheduledTimerWithTimeInterval:1.5target:self
selector:@selector(zoomToAnnotations) userInfo:nilrepeats:NO];
实现方法

-(void)zoomToAnnotations
{

MKPointAnnotation
*annotation =[[MKPointAnnotation
alloc]init];
annotation.coordinate=CLLocationCoordinate2DMake(self.latitude,
self.longitude);
annotation.title =
@"东仓花园";
annotation.subtitle =@"中国机械加工网";

// 指定新的显示区域
[self.mapView setRegion:MKCoordinateRegionMake(annotation.coordinate,
MKCoordinateSpanMake(0.02,0.02)) animated:YES];

//选中标注
[self.mapView selectAnnotation:annotation animated:YES];
[annotation release];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: