您好,欢迎来到二三娱乐。
搜索
您的当前位置:首页高德地图---显示、定位、逆编码

高德地图---显示、定位、逆编码

来源:二三娱乐

[AMapServices sharedServices].apiKey = @"80985a4a5ea3794dd8155f9a4973526b";

pragma mark - 创建地图

-(void)createMap{

///初始化地图
self.mapView = [[MAMapView alloc] initWithFrame:CGRectMake(0, self.topView.bottom, SCREENWIDTH, SCREENHEIGHT - self.topView.bottom)];
self.mapView.showsCompass = NO; // 隐藏指南针
self.mapView.showsScale = NO; // 隐藏比例尺
self.mapView.language = MAMapLanguageZhCN;
self.mapView.mapType = MAMapTypeStandard;
self.mapView.zoomLevel = 17;
self.mapView.delegate = self;
///如果您需要进入地图就显示定位小蓝点,则需要下面两行代码
self.mapView.showsUserLocation = YES;
self.mapView.userTrackingMode = MKUserTrackingModeFollow;
///把地图添加至view
[self.view addSubview:self.mapView];

}
// MARK: - 开始定位

  • (void)startLocation {

    self.locationManager = [[AMapLocationManager alloc] init];
    self.locationManager.delegate = self;
    self.locationManager.distanceFilter = kCLDistanceFilterNone;
    //要求CLLocationManager对象的返回结果尽可能的精准
    [self.locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
    [self.locationManager setPausesLocationUpdatesAutomatically:NO];

    [self.locationManager setAllowsBackgroundLocationUpdates:YES];
    //持续定位返回逆地理编码信息
    [self.locationManager setLocatingWithReGeocode:YES];
    [self.locationManager startUpdatingLocation];

    self.search = [[AMapSearchAPI alloc] init];
    self.search.delegate = self;
    }
    // MARK: - 接收位置更新

  • (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location
    {
    NSLog(@"location:{纬度:%f; 经度:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);

    //反编码
    AMapReGeocodeSearchRequest regeo = [[AMapReGeocodeSearchRequest alloc] init];
    regeo.location = [AMapGeoPoint locationWithLatitude:location.coordinate.latitude longitude:location.coordinate.longitude];
    NSLog(@"%f--%f",location.coordinate.latitude,location.coordinate.longitude);
    regeo.requireExtension = YES;
    //发起逆地理编码
    [self.search AMapReGoecodeSearch:regeo];
    }
    // MARK: - 逆编码
    /
    逆地理编码回调. */

  • (void)AMapSearchRequest:(id)request didFailWithError:(NSError *)error{

    NSLog(@"error:%@",error);
    }

Copyright © 2019- yule263.com 版权所有 湘ICP备2023023988号-1

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务