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

iOS中的地图属性设置以及位置的管理

2014-05-23 20:29 288 查看
上次只是大概说了一下显示地图的几种方法,以及如何设置地图的一些属性,今天跟大家分享的事如何在地图上进行位置注解以及进行位置管理。

// 完成位置反编码
CLGeocoder *geocoder = [[CLGeocoder alloc ]init];
CLLocation *location = [[CLLocation alloc]initWithLatitude:coordinate.latitude longitude:coordinate.longitude];
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
if (nil != error) {
NSLog(@"error info is %@",error);
}
for (CLPlacemark *placeMark in placemarks) {
NSLog(@"%@,%@,%@,%@,%@,%@,%@,%@,%@",placeMark.country,placeMark.areasOfInterest,placeMark.ocean,placeMark.ISOcountryCode,placeMark.inlandWater,placeMark.locality,placeMark.postalCode,placeMark.administrativeArea,placeMark.subLocality);
}
}];显示位置注解:这里用硬编码方式示例
MKPointAnnotation *pointAnnotation = [[MKPointAnnotation alloc]init];
pointAnnotation.coordinate = coordinate;
pointAnnotation.title = @"你好";
pointAnnotation.subtitle = @"世界";
[self.mapView addAnnotation:pointAnnotation];
使用MKMapViewDelegate来实现地图的位置信息以及大头针的显示
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *indentify = @"indentify";
MKPinAnnotationView *pinAnnotationView = (MKPinAnnotationView *)[mapView dequeueReusableAnnotationViewWithIdentifier:indentify];
if (nil == pinAnnotationView) {
pinAnnotationView = [[MKPinAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:indentify];
}
pinAnnotationView.image = [UIImage imageNamed:@"icon_nav_start"];

UIImageView *imageVew = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 40, 40)];
imageVew.image = [UIImage imageNamed:@"Icon"];
pinAnnotationView.leftCalloutAccessoryView = imageVew;

pinAnnotationView.animatesDrop = YES;
pinAnnotationView.pinColor = MKPinAnnotationColorPurple;
pinAnnotationView.canShowCallout = YES;

return pinAnnotationView;
}
当然在这之前还是要遵循CLLocationManagerDelegate,MKMapViewDelegate协议的

设置好后,运行即可看到大头针的位置显示视图了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  地图 mkmapview mapkit ios
相关文章推荐