5. Position acquisition and display of ArcGIS Runtime SDK for iOS 100.X tutorial series

        Generally speaking, when the ArcGIS map service is actually used, the coordinate system used will not be a common coordinate system. Government agencies may use the Beijing coordinate system more, but it will also be encrypted to a certain extent, so it is not recommended Use Apple's built-in positioning API for positioning operations to avoid the trouble of coordinate conversion. Of course, if you want to test or research, please explore by yourself. This example uses the positioning function that comes with ArcGIS:

@property (nonatomic, strong) NSTimer *locationCatchTimer;//定位采集定时器

[self.mapView.locationDisplay setDataSourceStatusChangedHandler:^(BOOL started) {
        if (started) {
            [weakSelf.mapView.locationDisplay startWithCompletion:nil];
        }
    }];
    [self.mapView.locationDisplay.dataSource startWithCompletion:nil];
    self.locationCatchTimer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(catchLocation) userInfo:nil repeats:YES];
    [[NSRunLoop currentRunLoop]addTimer:self.locationCatchTimer forMode:NSDefaultRunLoopMode];

Above, I used the timer to collect the positioning information instead of obtaining it in the block callback, because the positioning information of the block callback is not timely or even empty.

The method called by the timer:

- (void)catchLocation {
    AGSPoint *currentLocationPoint = [self.mapView.locationDisplay mapLocation];
    //该例适用于启动地图后第一次定位,多次定位的判断可自行处理逻辑
    if (currentLocationPoint.x != 0) {
        [self.locationCatchTimer invalidate];
        //此处的currentLocationPoint.y-1000000是一个例子,针对企业会对坐标系进行额外加密的情况
        //未加密,则无需减少或增加
        //具体怎么操作,可询问服务发布者
        AGSPoint* myMarkerPoint = [AGSPoint pointWithX:currentLocationPoint.x y:(currentLocationPoint.y-1000000) spatialReference:self.mapView.spatialReference];
        //不使用自带的定位显示,因为加密了的定位信息,所以自带显示的也不准
        self.mapView.locationDisplay.showLocation = NO;
        //拉大地图聚焦到定位位置
        [self.mapView setViewpointCenter:myMarkerPoint scale:2000 completion:^(BOOL finished) {
            
        }];
        //自己创建一个定位图标展示到地图上
        AGSPictureMarkerSymbol *pictureSymbol = [[AGSPictureMarkerSymbol alloc] initWithImage:[UIImage imageNamed:@"marker-blue"]];
        AGSGraphic *locationGraphic = [[AGSGraphic alloc] initWithGeometry:myMarkerPoint symbol:pictureSymbol attributes:nil];
        //overlayer是渲染图层,可参见教程第一篇文章
        [self.overlayer.graphics addObject:locationGraphic];
        //定位服务停止
        self.locationCatchTimer = nil;
        [self.mapView.locationDisplay.dataSource stop];
        [self.mapView.locationDisplay stop];
    }
}

 

Guess you like

Origin blog.csdn.net/qq_31672459/article/details/79739508