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