在ios中使用手机定位获得的经纬度坐标 通过 arcgis的api 显示在wgs84 坐标系的地图上。

1. 底图做的 是 wgs84 坐标系。

2. ios设备通过gps定位获得的坐标是 经纬度。

3.把经纬度坐标 转换成 墨卡托坐标。然后通过 

[self.mapViewcenterAtPoint:mappoint animated:YES]; 

来显示点 


相关代码:

    CGPoint coord;
    coord.x=newLocation.coordinate.longitude;
    coord.y=newLocation.coordinate.latitude;
    NSLog(@"x=%f",coord.x);
    NSLog(@"y=%f",coord.y);
    CGPoint mecPoint=[self lonLat2Mercator:coord];
    AGSSpatialReference *wgs84SpatialReference =  [[AGSSpatialReference alloc] initWithWKID:4326];
    AGSPoint *mappoint =[[AGSPoint alloc] initWithX:mecPoint.x y:mecPoint.y spatialReference:wgs84SpatialReference];
    NSLog(@"输出点的x坐标=%f,y坐标=%f",mappoint.x,mappoint.y);
    
    [self.graphicsLayer removeAllGraphics];
    AGSPictureMarkerSymbol *pt;
    pt = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:@"ArcGIS.bundle/LocationDisplay.png"];
    AGSGraphic *LocationDisplay = [[AGSGraphic alloc] initWithGeometry:mappoint symbol:pt attributes:nil infoTemplateDelegate:nil];
    
    [self.graphicsLayer addGraphic:LocationDisplay];



//经纬度转墨卡托
-(CGPoint )lonLat2Mercator:(CGPoint ) lonLat
{
    CGPoint  mercator;
    double x = lonLat.x *20037508.34/180;
    double y = log(tan((90+lonLat.y)*M_PI/360))/(M_PI/180);
    y = y *20037508.34/180;
    mercator.x = x;
    mercator.y = y;
    return mercator ;
}


你可能感兴趣的:(在ios中使用手机定位获得的经纬度坐标 通过 arcgis的api 显示在wgs84 坐标系的地图上。)