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

本文介绍如何将iOS设备通过GPS获取的经纬度坐标转换为墨卡托坐标,并利用地图视图显示这些坐标点。文章详细展示了从获取地理位置到在地图上标记位置的全过程,包括坐标转换算法和地图视图的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 ;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值