ArcGIS Runtime SDK for iOS如何自定义定位点实现位置偏移

用户希望对设备获取的定位点坐标在绘制到地图上之前做一定的偏移,咨询如何实现。
已邀请:

马克玲

赞同来自:

【解决办法】:
要实现自定义控制定位点坐标,最关键的是实现自定义位置数据源。在自定义位置数据源类中实现
CLLocationManagerDelegate委托,进而通过委托方法来调整定位点信息。

具体参考代码:
1) CustomLocationDataSource.h



//

//  CustomLocaitonDataSource.h

//  CustomLocationDataSouce

//

//  Created by makl on 16/1/12.

//  Copyright (c) 2016年 Esri. All rights reserved.

//



#import <Foundation/Foundation.h>

#import <ArcGIS/ArcGIS.h>

@interface CustomLocaitonDataSource : NSObject<AGSLocationDisplayDataSource,CLLocationManagerDelegate>

@property(weak,nonatomic) id<AGSLocationDisplayDataSourceDelegate> delegate;

@property(strong, nonatomic,readonly) NSError* error;

@property(strong,nonatomic) CLLocationManager* locationManager;

@property(assign, nonatomic,getter = isStarted) BOOL started;

-(void)start;

-(void)stop;

@End



2)CustomLocationDataSource.m



//

//  CustomLocaitonDataSource.m

//  CustomLocationDataSouce

//

//  Created by makl on 16/1/12.

//  Copyright (c) 2016年 Esri. All rights reserved.

//



#import CustomLocaitonDataSource.h

#import <ArcGIS/ArcGIS.h>

#import <CoreLocation/CoreLocation.h>





@implementation CustomLocaitonDataSource





-(id)init{

    

    if(self = [super init]){

        

    self.locationManager = [[CLLocationManager alloc] init];

    

    self.locationManager.delegate = self;

    }

    

    return self;



}



- (void)locationManager:(CLLocationManager *)manager

    didUpdateToLocation:(CLLocation *)newLocation

           fromLocation:(CLLocation *)oldLocation{

    //CLLocation* newLL = newLocation;

   }



- (void)locationManager:(CLLocationManager *)manager

     didUpdateLocations:(NSArray *)locations{

    

    AGSLocation* location = [AGSLocation locationWithCLLocation:locations[0]];

    

    //实现客户化转换算法

    AGSPoint *verifyPoint = [AGSPoint pointWithX:location.point.x+10 y:location.point.y+10 spatialReference:[AGSSpatialReference spatialReferenceWithWKID:4326]];

    [location setPoint:verifyPoint];

    [self.delegate locationDisplayDataSource:self didUpdateWithLocation:location];



}



- (void)locationManager:(CLLocationManager *)manager

       didUpdateHeading:(CLHeading *)newHeading{

    

    [self.delegate locationDisplayDataSource:self didUpdateWithHeading:newHeading.trueHeading];

}





-(void)start{

    

    [self.locationManager startUpdatingHeading];

    [self.locationManager startUpdatingLocation];

    [self.delegate locationDisplayDataSourceStarted:self];

    

    self.started = true;

    

}



-(void)stop{

    

    [self.locationManager stopUpdatingHeading];

    [self.locationManager stopUpdatingLocation];

    [self.delegate locationDisplayDataSourceStopped:self];

    

    self.started = false;

}



@End



3) 位置开启




-(void) mapViewDidLoad:(AGSMapView*)mapView {

    

    CustomLocaitonDataSource* customLocaitonDataSource = [[CustomLocaitonDataSource alloc] init];

    self.mapView.locationDisplay.dataSource = customLocaitonDataSource;

    

    // Enable location display on the map

    [self.mapView.locationDisplay startDataSource];

    self.mapView.locationDisplay.autoPanMode = AGSLocationDisplayAutoPanModeDefault;

   

}

要回复问题请先登录注册