定位标注自己的位置 自定义大头针 反地理编码等

用的是系统的mapview,因返回的是火星坐标,在进行反地理编码时出现偏差,用网上的一些坐标转换发现还是不准确,无奈只能引入高德地图的AMapSearch进行反地理编码。想想前两天出去面试,面试官一本正经否定我,说mapview是地球坐标  CLLocation是火星坐标  我也是醉的不行不行的了。。。废话不多说了直接上代码

(一)

#import "AijeeSuperViewController.h"

#import "AMapSearchKit.h"

@interface LocateForYourSelfVC : AijeeSuperViewController

@property (nonatomic, copy) void (^callBack)(id obc);

@property (nonatomic , copy) AMapSearchAPI * search;

@property (nonatomic, strong) CLLocation * location;

@property (nonatomic, strong) NSString * strBusinnessName;

@end

(二)

#import "LocateForYourSelfVC.h"

#import

#import "AMapSearchKit.h"

#import "KCAnnotation.h"//自定义大头针

@interface LocateForYourSelfVC ()

{

MKMapView* mapview;

CLLocationCoordinate2D coordi;

CLLocationCoordinate2D coor2self;//纪录自己的坐标位置

UILabel * addressLabel;

BOOL isOK;//是否可以点击确定 上传定位信息

BOOL isFirst;

BOOL isOut;//判断用户是否滑动地图出了边界

//    AMapReGeocodeSearchRequest *regeo;

UIImageView * imagvi;

UILabel * labelAlertUp;

UIImageView * addressImageview;

UIButton * clickBackSelf;

KCAnnotation *annotation1;

CLLocationCoordinate2D coords;//记录商户详情天转过来时  商户的坐标

}

@end

@implementation LocateForYourSelfVC

- (void)viewDidLoad {

//配置用户Key

[AMapSearchServices sharedServices].apiKey = @"";

//初始化检索对象

_search = [[AMapSearchAPI alloc] init];

_search.delegate = self;

[super viewDidLoad];

self.titleText.text = @"地图定位";

self.navigationItem.leftBarButtonItem = ({

UIImage* image= [UIImage imageNamed:@"aijeeBtnbackimage"];

CGRect backframe= CGRectMake(0, 2, 40, 40);

UIButton* dismissButton= [UIButton buttonWithType:UIButtonTypeCustom];

dismissButton.frame = backframe;

[dismissButton setBackgroundImage:image forState:UIControlStateNormal];

[dismissButton setBackgroundColor:ColoClear];

[dismissButton addTarget:self action:@selector(dismissButtonAction:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *dismissBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:dismissButton];

dismissBarButtonItem;

});

//初始化地图视图

mapview = [[MKMapView alloc]initWithFrame:self.view.bounds];

//地图的代理方法

mapview.delegate = self;

//是否显示当前的位置

mapview.showsUserLocation = YES;

//地图的类型, iOS开发中自带的地图

/* MKMapTypeStandard 标准地图 MKMapTypeSatellite 卫星地图 MKMapTypeHybrid 混合地图 */

mapview.mapType = MKMapTypeStandard;

[self.view addSubview:mapview];

mapview.userTrackingMode =  MKUserTrackingModeFollow;

//设置不允许地图旋转

mapview.rotateEnabled = NO;

if (!self.location) {

self.navigationItem.rightBarButtonItem = ({

UIBarButtonItem *noneBarButtonitem;

noneBarButtonitem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)];

[noneBarButtonitem setTintColor:ColoWhite];

[noneBarButtonitem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.f],NSForegroundColorAttributeName:ColoWhite} forState:UIControlStateNormal];

noneBarButtonitem;

});

labelAlertUp = [[UILabel alloc]initWithFrame:CGRectMake(0, 64, SizeWidth, 40)];

labelAlertUp.text = @"移动地图,点击确定后重新定位";

labelAlertUp.font = [UIFont systemFontOfSize:14];

labelAlertUp.textAlignment = NSTextAlignmentCenter;

labelAlertUp.backgroundColor = [UIColor colorWithRed:0.00f green:0.00f blue:0.00f alpha:0.50f];

labelAlertUp.textColor = ColoWhite;

[self.view addSubview:labelAlertUp];

addressImageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, Sizeheight-50, SizeWidth-20, 40)];

addressImageview.image = [UIImage imageNamed:@"LocateDonwIV"];

[self.view addSubview:addressImageview];

imagvi = [[UIImageView alloc]initWithFrame:CGRectMake((SizeWidth-27)/2.0, Sizeheight/2.0, 27, 37.5)];

imagvi.image = [UIImage imageNamed:@"LocateForSelf"];

[self.view addSubview:imagvi];

UIImageView * addrIV = [[UIImageView alloc]initWithFrame:CGRectMake(12, 10, 16, 20)];

addrIV.image = [UIImage imageNamed:@"LocateSmallIV"];

[addressImageview addSubview:addrIV];

addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(addrIV.frame)+10, 0, SizeWidth-20-28-10, 40)];

[addressImageview addSubview:addressLabel];

}

[NSTimer scheduledTimerWithTimeInterval:3.f target:self selector:@selector(ClickCreartime) userInfo:nil repeats:NO];

if (self.location)//用一个参数判断是从哪里跳转此页面的

{

//只在第一次进这个控制器的时候 在这个指定位置添加大头针

//用于其他界面复用此界面  定位指定的坐标位置

coords = CLLocationCoordinate2DMake(self.location.coordinate.latitude,self.location.coordinate.longitude);//39.9884490052,116.4315448786

float zoomLevel = 0.02;

MKCoordinateRegion region = MKCoordinateRegionMake(coords, MKCoordinateSpanMake(zoomLevel, zoomLevel));

[mapview setRegion:[mapview regionThatFits:region] animated:YES];

annotation1 = [[KCAnnotation alloc]init];

if (!self.strBusinnessName) {

self.strBusinnessName = @"商户";

}

annotation1.title = self.strBusinnessName;

annotation1.subtitle = @"地址";

annotation1.coordinate = coords;

annotation1.image=[UIImage imageNamed:@"LocateForBusiness"];

[mapview addAnnotation:annotation1];

[mapview selectAnnotation:annotation1 animated:YES];

AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];

regeo.location = [AMapGeoPoint locationWithLatitude:coords.latitude longitude:coords.longitude];

regeo.radius = 10000;

regeo.requireExtension = YES;

//发起逆地理编码

[_search AMapReGoecodeSearch: regeo];

}

}

-(void)ClickCreartime

{

clickBackSelf = [UIButton buttonWithType:UIButtonTypeCustom];

[clickBackSelf setFrame:CGRectMake(SizeWidth-55, Sizeheight-110, 45, 45)];

[clickBackSelf addTarget:self action:@selector(clickBackSelf:) forControlEvents:UIControlEventTouchUpInside];

[clickBackSelf setBackgroundImage:[UIImage imageNamed:@"LocateSelf"] forState:UIControlStateNormal];

[self.view addSubview:clickBackSelf];

if (self.location) {

clickBackSelf.frame = CGRectMake(SizeWidth-55, Sizeheight-87.5, 45, 45);

}

}

#pragma mark - click button

- (void)clickBackSelf:(UIButton *)sender{

[mapview setCenterCoordinate:mapview.userLocation.location.coordinate animated:YES];

}

- (void)dismissButtonAction:(UIButton *)sender

{

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

}

- (void)buttonClicked:(UIButton *)sender{

if (isOK) {

[self.navigationController dismissViewControllerAnimated:YES completion:^{

}];

NSString *strLat = [NSString stringWithFormat:@"%f",coordi.latitude];

NSString *strLong = [NSString stringWithFormat:@"%f",coordi.longitude];

NSMutableDictionary *dicLotion = [[NSMutableDictionary alloc] init];

[dicLotion setValue:strLat forKey:@"latitude"];

[dicLotion setValue:strLong forKey:@"longitude"];

[dicLotion setValue:addressLabel.text forKey:@"strAddress"];

//        SBJson4Writer *writer = [[SBJson4Writer alloc]init];

self.callBack(dicLotion);

}else{

UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选用附近的位置" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];

[alert show];

}

}

#pragma mark - deleget

//更新用户位置,只要用户位置改变则调用此方法(包括第一次定位到用户位置)

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{

if (!isFirst)

{

if (!self.location)//用一个参数判断是从哪里跳转此页面的

{

coordi = (CLLocationCoordinate2D){userLocation.location.coordinate.latitude, userLocation.location.coordinate.longitude};

coor2self = coordi;

MKCoordinateSpan span = {0.005,0.005};

MKCoordinateRegion region = {coordi,span};

//mapview.zoomEnabled = NO;

//mapview.scrollEnabled = NO;

[mapview setRegion:region];

//构造AMapReGeocodeSearchRequest对象

AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];

regeo.location = [AMapGeoPoint locationWithLatitude:coordi.latitude longitude:coordi.longitude];

regeo.radius = 10000;

regeo.requireExtension = YES;

//发起逆地理编码

[_search AMapReGoecodeSearch: regeo];

}

}

isFirst = YES;

}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation{

//由于当前位置的标注也是一个大头针,所以此时需要判断,此代理方法返回nil使用默认大头针视图

if ([annotation isKindOfClass:[KCAnnotation class]])

{

if (self.location)

{

static NSString *key1=@"AnnotationKey1";

MKAnnotationView *annotationView = [mapview dequeueReusableAnnotationViewWithIdentifier:key1];

//如果缓存池中不存在则新建

if (!annotationView) {

annotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:key1];

annotationView.canShowCallout = true;//允许交互点击

annotationView.calloutOffset = CGPointMake(0, -10);//定义详情视图偏移量

//annotationView.leftCalloutAccessoryView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"gift_bag"]];//定义详情左侧视图

}

//修改大头针视图

//重新设置此类大头针视图的大头针模型(因为有可能是从缓存池中取出来的,位置是放到缓存池时的位置)

annotationView.annotation = annotation;

annotationView.image = ((KCAnnotation *)annotation).image;//设置大头针视图的图片

return annotationView;

}

else

{

return nil;

}

}

else

{

return nil;

}

}

//可以打印经纬度的跨度,用来测试当前视图下地经纬度跨度是多少,然后用于上面的MKCoordinateSpanMake方法中

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{

if (!self.location) {

double x = mapView.center.x;

double y = mapView.center.y;

CGPoint point=CGPointMake( x, y);

coordi = [mapview convertPoint:point toCoordinateFromView:mapview];

AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];

regeo.location = [AMapGeoPoint locationWithLatitude:coordi.latitude longitude:coordi.longitude];

regeo.radius = 10000;

regeo.requireExtension = YES;

//发起逆地理编码

[_search AMapReGoecodeSearch: regeo];

//第一个坐标

CLLocation *current=[[CLLocation alloc] initWithLatitude:coordi.latitude longitude:coordi.longitude];

//第二个坐标

CLLocation *before=[[CLLocation alloc] initWithLatitude:coor2self.latitude longitude:coor2self.longitude];

// 计算距离

CLLocationDistance meters=[current distanceFromLocation:before];

//    MKMapPoint point1 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(coordi.latitude,coordi.longitude));

//

//    MKMapPoint point2 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(coor2self.latitude,coor2self.longitude));

//    //2.计算距离

//    CLLocationDistance distance = MKMetersBetweenMapPoints(point1,point2);

DLog(@"%f",meters);

if (meters > 1000) {

if (isOK) {

UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选用附近的位置" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];

[alert show];

}

isOK = NO;

}

else{

isOK = YES;

}

}

}

//实现逆地理编码的回调函数

- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response

{

if(response.regeocode != nil)

{

//通过AMapReGeocodeSearchResponse对象处理搜索结果

AMapReGeocode *regeocode=response.regeocode;

NSLog(@"%@",regeocode.formattedAddress);

addressLabel.text = regeocode.formattedAddress;

if (self.location)

{

annotation1.subtitle = regeocode.formattedAddress;

}

}

}

(三)

#import

#import

@interface KCAnnotation : NSObject

@property (nonatomic) CLLocationCoordinate2D coordinate;

@property (nonatomic, copy) NSString *title;

@property (nonatomic, copy) NSString *subtitle;

#pragma mark 自定义一个图片属性在创建大头针视图时使用

@property (nonatomic,strong) UIImage *image;

@end

用的是系统的mapview,因返回的是火星坐标,在进行反地理编码时出现偏差,用网上的一些坐标转换发现还是不准确,无奈只能引入高德地图的AMapSearch进行反地理编码。想想前两天出去面试,面试官一本正经否定我,说mapview是地球坐标  CLLocation是火星坐标  我也是醉的不行不行的了。。。废话不多说了直接上代码

(一)

#import "AijeeSuperViewController.h"

#import "AMapSearchKit.h"

@interface LocateForYourSelfVC : AijeeSuperViewController

@property (nonatomic, copy) void (^callBack)(id obc);

@property (nonatomic , copy) AMapSearchAPI * search;

@property (nonatomic, strong) CLLocation * location;

@property (nonatomic, strong) NSString * strBusinnessName;

@end

(二)

#import "LocateForYourSelfVC.h"

#import

#import "AMapSearchKit.h"

#import "KCAnnotation.h"//自定义大头针

@interface LocateForYourSelfVC ()

{

MKMapView* mapview;

CLLocationCoordinate2D coordi;

CLLocationCoordinate2D coor2self;//纪录自己的坐标位置

UILabel * addressLabel;

BOOL isOK;//是否可以点击确定 上传定位信息

BOOL isFirst;

BOOL isOut;//判断用户是否滑动地图出了边界

//    AMapReGeocodeSearchRequest *regeo;

UIImageView * imagvi;

UILabel * labelAlertUp;

UIImageView * addressImageview;

UIButton * clickBackSelf;

KCAnnotation *annotation1;

CLLocationCoordinate2D coords;//记录商户详情天转过来时  商户的坐标

}

@end

@implementation LocateForYourSelfVC

- (void)viewDidLoad {

//配置用户Key

[AMapSearchServices sharedServices].apiKey = @"";

//初始化检索对象

_search = [[AMapSearchAPI alloc] init];

_search.delegate = self;

[super viewDidLoad];

self.titleText.text = @"地图定位";

self.navigationItem.leftBarButtonItem = ({

UIImage* image= [UIImage imageNamed:@"aijeeBtnbackimage"];

CGRect backframe= CGRectMake(0, 2, 40, 40);

UIButton* dismissButton= [UIButton buttonWithType:UIButtonTypeCustom];

dismissButton.frame = backframe;

[dismissButton setBackgroundImage:image forState:UIControlStateNormal];

[dismissButton setBackgroundColor:ColoClear];

[dismissButton addTarget:self action:@selector(dismissButtonAction:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *dismissBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:dismissButton];

dismissBarButtonItem;

});

//初始化地图视图

mapview = [[MKMapView alloc]initWithFrame:self.view.bounds];

//地图的代理方法

mapview.delegate = self;

//是否显示当前的位置

mapview.showsUserLocation = YES;

//地图的类型, iOS开发中自带的地图

/* MKMapTypeStandard 标准地图 MKMapTypeSatellite 卫星地图 MKMapTypeHybrid 混合地图 */

mapview.mapType = MKMapTypeStandard;

[self.view addSubview:mapview];

mapview.userTrackingMode =  MKUserTrackingModeFollow;

//设置不允许地图旋转

mapview.rotateEnabled = NO;

if (!self.location) {

self.navigationItem.rightBarButtonItem = ({

UIBarButtonItem *noneBarButtonitem;

noneBarButtonitem = [[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)];

[noneBarButtonitem setTintColor:ColoWhite];

[noneBarButtonitem setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:14.f],NSForegroundColorAttributeName:ColoWhite} forState:UIControlStateNormal];

noneBarButtonitem;

});

labelAlertUp = [[UILabel alloc]initWithFrame:CGRectMake(0, 64, SizeWidth, 40)];

labelAlertUp.text = @"移动地图,点击确定后重新定位";

labelAlertUp.font = [UIFont systemFontOfSize:14];

labelAlertUp.textAlignment = NSTextAlignmentCenter;

labelAlertUp.backgroundColor = [UIColor colorWithRed:0.00f green:0.00f blue:0.00f alpha:0.50f];

labelAlertUp.textColor = ColoWhite;

[self.view addSubview:labelAlertUp];

addressImageview = [[UIImageView alloc]initWithFrame:CGRectMake(10, Sizeheight-50, SizeWidth-20, 40)];

addressImageview.image = [UIImage imageNamed:@"LocateDonwIV"];

[self.view addSubview:addressImageview];

imagvi = [[UIImageView alloc]initWithFrame:CGRectMake((SizeWidth-27)/2.0, Sizeheight/2.0, 27, 37.5)];

imagvi.image = [UIImage imageNamed:@"LocateForSelf"];

[self.view addSubview:imagvi];

UIImageView * addrIV = [[UIImageView alloc]initWithFrame:CGRectMake(12, 10, 16, 20)];

addrIV.image = [UIImage imageNamed:@"LocateSmallIV"];

[addressImageview addSubview:addrIV];

addressLabel = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMaxX(addrIV.frame)+10, 0, SizeWidth-20-28-10, 40)];

[addressImageview addSubview:addressLabel];

}

[NSTimer scheduledTimerWithTimeInterval:3.f target:self selector:@selector(ClickCreartime) userInfo:nil repeats:NO];

if (self.location)//用一个参数判断是从哪里跳转此页面的

{

//只在第一次进这个控制器的时候 在这个指定位置添加大头针

//用于其他界面复用此界面  定位指定的坐标位置

coords = CLLocationCoordinate2DMake(self.location.coordinate.latitude,self.location.coordinate.longitude);//39.9884490052,116.4315448786

float zoomLevel = 0.02;

MKCoordinateRegion region = MKCoordinateRegionMake(coords, MKCoordinateSpanMake(zoomLevel, zoomLevel));

[mapview setRegion:[mapview regionThatFits:region] animated:YES];

annotation1 = [[KCAnnotation alloc]init];

if (!self.strBusinnessName) {

self.strBusinnessName = @"商户";

}

annotation1.title = self.strBusinnessName;

annotation1.subtitle = @"地址";

annotation1.coordinate = coords;

annotation1.image=[UIImage imageNamed:@"LocateForBusiness"];

[mapview addAnnotation:annotation1];

[mapview selectAnnotation:annotation1 animated:YES];

AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];

regeo.location = [AMapGeoPoint locationWithLatitude:coords.latitude longitude:coords.longitude];

regeo.radius = 10000;

regeo.requireExtension = YES;

//发起逆地理编码

[_search AMapReGoecodeSearch: regeo];

}

}

-(void)ClickCreartime

{

clickBackSelf = [UIButton buttonWithType:UIButtonTypeCustom];

[clickBackSelf setFrame:CGRectMake(SizeWidth-55, Sizeheight-110, 45, 45)];

[clickBackSelf addTarget:self action:@selector(clickBackSelf:) forControlEvents:UIControlEventTouchUpInside];

[clickBackSelf setBackgroundImage:[UIImage imageNamed:@"LocateSelf"] forState:UIControlStateNormal];

[self.view addSubview:clickBackSelf];

if (self.location) {

clickBackSelf.frame = CGRectMake(SizeWidth-55, Sizeheight-87.5, 45, 45);

}

}

#pragma mark - click button

- (void)clickBackSelf:(UIButton *)sender{

[mapview setCenterCoordinate:mapview.userLocation.location.coordinate animated:YES];

}

- (void)dismissButtonAction:(UIButton *)sender

{

[self.navigationController dismissViewControllerAnimated:YES completion:nil];

}

- (void)buttonClicked:(UIButton *)sender{

if (isOK) {

[self.navigationController dismissViewControllerAnimated:YES completion:^{

}];

NSString *strLat = [NSString stringWithFormat:@"%f",coordi.latitude];

NSString *strLong = [NSString stringWithFormat:@"%f",coordi.longitude];

NSMutableDictionary *dicLotion = [[NSMutableDictionary alloc] init];

[dicLotion setValue:strLat forKey:@"latitude"];

[dicLotion setValue:strLong forKey:@"longitude"];

[dicLotion setValue:addressLabel.text forKey:@"strAddress"];

//        SBJson4Writer *writer = [[SBJson4Writer alloc]init];

self.callBack(dicLotion);

}else{

UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选用附近的位置" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];

[alert show];

}

}

#pragma mark - deleget

//更新用户位置,只要用户位置改变则调用此方法(包括第一次定位到用户位置)

-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation{

if (!isFirst)

{

if (!self.location)//用一个参数判断是从哪里跳转此页面的

{

coordi = (CLLocationCoordinate2D){userLocation.location.coordinate.latitude, userLocation.location.coordinate.longitude};

coor2self = coordi;

MKCoordinateSpan span = {0.005,0.005};

MKCoordinateRegion region = {coordi,span};

//mapview.zoomEnabled = NO;

//mapview.scrollEnabled = NO;

[mapview setRegion:region];

//构造AMapReGeocodeSearchRequest对象

AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];

regeo.location = [AMapGeoPoint locationWithLatitude:coordi.latitude longitude:coordi.longitude];

regeo.radius = 10000;

regeo.requireExtension = YES;

//发起逆地理编码

[_search AMapReGoecodeSearch: regeo];

}

}

isFirst = YES;

}

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id )annotation{

//由于当前位置的标注也是一个大头针,所以此时需要判断,此代理方法返回nil使用默认大头针视图

if ([annotation isKindOfClass:[KCAnnotation class]])

{

if (self.location)

{

static NSString *key1=@"AnnotationKey1";

MKAnnotationView *annotationView = [mapview dequeueReusableAnnotationViewWithIdentifier:key1];

//如果缓存池中不存在则新建

if (!annotationView) {

annotationView = [[MKAnnotationView alloc]initWithAnnotation:annotation reuseIdentifier:key1];

annotationView.canShowCallout = true;//允许交互点击

annotationView.calloutOffset = CGPointMake(0, -10);//定义详情视图偏移量

//annotationView.leftCalloutAccessoryView=[[UIImageView alloc]initWithImage:[UIImage imageNamed:@"gift_bag"]];//定义详情左侧视图

}

//修改大头针视图

//重新设置此类大头针视图的大头针模型(因为有可能是从缓存池中取出来的,位置是放到缓存池时的位置)

annotationView.annotation = annotation;

annotationView.image = ((KCAnnotation *)annotation).image;//设置大头针视图的图片

return annotationView;

}

else

{

return nil;

}

}

else

{

return nil;

}

}

//可以打印经纬度的跨度,用来测试当前视图下地经纬度跨度是多少,然后用于上面的MKCoordinateSpanMake方法中

-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated{

if (!self.location) {

double x = mapView.center.x;

double y = mapView.center.y;

CGPoint point=CGPointMake( x, y);

coordi = [mapview convertPoint:point toCoordinateFromView:mapview];

AMapReGeocodeSearchRequest *regeo = [[AMapReGeocodeSearchRequest alloc] init];

regeo.location = [AMapGeoPoint locationWithLatitude:coordi.latitude longitude:coordi.longitude];

regeo.radius = 10000;

regeo.requireExtension = YES;

//发起逆地理编码

[_search AMapReGoecodeSearch: regeo];

//第一个坐标

CLLocation *current=[[CLLocation alloc] initWithLatitude:coordi.latitude longitude:coordi.longitude];

//第二个坐标

CLLocation *before=[[CLLocation alloc] initWithLatitude:coor2self.latitude longitude:coor2self.longitude];

// 计算距离

CLLocationDistance meters=[current distanceFromLocation:before];

//    MKMapPoint point1 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(coordi.latitude,coordi.longitude));

//

//    MKMapPoint point2 = MKMapPointForCoordinate(CLLocationCoordinate2DMake(coor2self.latitude,coor2self.longitude));

//    //2.计算距离

//    CLLocationDistance distance = MKMetersBetweenMapPoints(point1,point2);

DLog(@"%f",meters);

if (meters > 1000) {

if (isOK) {

UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"提示" message:@"请选用附近的位置" delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil, nil];

[alert show];

}

isOK = NO;

}

else{

isOK = YES;

}

}

}

//实现逆地理编码的回调函数

- (void)onReGeocodeSearchDone:(AMapReGeocodeSearchRequest *)request response:(AMapReGeocodeSearchResponse *)response

{

if(response.regeocode != nil)

{

//通过AMapReGeocodeSearchResponse对象处理搜索结果

AMapReGeocode *regeocode=response.regeocode;

NSLog(@"%@",regeocode.formattedAddress);

addressLabel.text = regeocode.formattedAddress;

if (self.location)

{

annotation1.subtitle = regeocode.formattedAddress;

}

}

}

(三)

#import

#import

@interface KCAnnotation : NSObject

@property (nonatomic) CLLocationCoordinate2D coordinate;

@property (nonatomic, copy) NSString *title;

@property (nonatomic, copy) NSString *subtitle;

#pragma mark 自定义一个图片属性在创建大头针视图时使用

@property (nonatomic,strong) UIImage *image;

@end


相关文章

  • 工程测量毕业设计
  • 湖南软件职业学院 毕业设计(作业) 毕 业 学 生 院系所 学 所 在 学生提 交 选 题 : 湘潭市地名地址数据库建设的技术设计 姓 名 : 康靖 名称 : 测绘工程系 专 业 : 工程测量与监理 班 级 : 1203班 学号 : [1* ...查看


  • 规划行业总体方案
  • 规划行业系统总体方案 北京东方道迩信息技术股份有限公司 2014年2月 目录 1.前言 . .......................................................................... ...查看


  • 有关数字城管业务知识解答
  • 有关数字城管业务知识解答 一.何为数字化城市综合管理与指挥系统? 二.城市管理部件和事件各有多少大类和多少小类? 三.何为城市管理部件?何为城市管理事件? 四.何为城市部件管理法? 五.何为事件管理法? 六.我县数字化城管业务系统具体有哪些 ...查看


  • 计算机地图制图
  • 计算机地图制图 计算机地图制图(Computer-Aided Cartography ,简称CAC )又称数字化制图.计算机辅助制图等,简称为机助制图.简单的讲计算机地图制图是以地图学基本原理为基础,应用计算机和图形输入输出设备,从事地图制 ...查看


  • 县级土地利用总体规划数据库标准708new
  • ICS 备案号: TD 县级土地利用总体规划数据库标准 Standard for Database of the County -level General Land Use Planning (报批稿) 中华人民共和国国土资源部 发布 目 ...查看


  • 地理信息系统考试复习题
  • 一.名词解释(共25分,每题5分) 1.地理信息系统:具有信息系统的各种特点,是一种决策支持系统.地理信息系统是空间数据的管理系统. 2.元数据:元数据就是"关于数据的数据",描述数据的数据. 3.栅格数据结构:栅格结构 ...查看


  • 复变函数论文 1
  • 河南城建学院 测 会 与 城 市 空 间 信 息 系 -论复变函数在专业中的应用 <复变函数>结课论文 摘 要:1. 复变函数的概况 2. 复变函数的广泛应用 3. 复变函数在本专业中的应用 关键词:1. 复变函数 2.GIS ...查看


  • 基于GIS的城市地下管线横纵断面分析
  • 第33卷第3期2010年6月 测绘与空间地理信息 GEOMA TICS &SPA T I AL I N FORMA TI ON TECHNOLOGY Vol . 33, No . 3Jun . , 2010 基于G IS 的城市地下 ...查看


  • 连杆夹具课程设计
  • 韶 关 学 院 课程设计说明书 题 目:汽车连杆的机械加工工艺规程及工艺 装备设计 学生姓名:林鸿海 学 号:[1**********] 系(院):物理与机电工程学院机电系 专 业:机械设计制造及其自动化 班 级:3班 指导教师姓名及职称: ...查看


热门内容