在AGSMapView iOS上绘制AGSPoint

时间:2015-06-05 09:12:49

标签: ios

我将arcGis个sdks集成到我的iOS项目中 但是当试图将agsPoint绘制到某个点时,它总是密谋到(0,0)。我认为这是由于空间参考

提前致谢

AGSSpatialReference *spatialRefference = [AGSSpatialReference spatialReferenceWithWKID: 102100];
//  4326 ,102100

AGSPoint *newPoint=[[AGSPoint alloc]init];
//newPoint2= [AGSPoint pointWithX:75.871952 y:22.685667 spatialReference:spatialRefference];
//newPoint= [AGSPoint pointWithLocation:locInstance.locationManager.location];

[myMap zoomToResolution:2.0 withCenterPoint:newPoint animated:YES];

//1. Create Graphics Layer
AGSGraphicsLayer* myGraphicsLayer = [[AGSGraphicsLayer alloc]initWithSpatialReference:newPoint.spatialReference];



[myMap addMapLayer:myGraphicsLayer withName:@"Graphics Layer"];

//2. Create a marker symbol to be used by our Graphic
AGSSimpleMarkerSymbol *myMarkerSymbol =[AGSSimpleMarkerSymbol simpleMarkerSymbol];

myMarkerSymbol.color = [UIColor blueColor];
myMarkerSymbol.style = AGSSimpleMarkerSymbolStyleDiamond;
myMarkerSymbol.outline.color = [UIColor whiteColor];
myMarkerSymbol.outline.width = 1;

//3. Create an AGSPoint (which inherits from AGSGeometry) that
//defines where the Graphic will be drawn

AGSPoint* locPoint =[[AGSPoint alloc]init];

locPoint=[AGSPoint pointWithLocation:locInstance.bestEffortAtLocation];


AGSGeometryEngine* engine = [AGSGeometryEngine defaultGeometryEngine];

AGSGeometry *pointToDraw= [engine projectGeometry:locPoint                                              toSpatialReference:newPoint.spatialReference];

//4. Create the Graphic, using the symbol and
//geometry created earlier

//[AGSGraphic graphicWithGeometry:locPoint symbol:myMarkerSymbol attributes:attributes];

AGSGraphic* myGraphic =  [[AGSGraphic alloc]init];
            myGraphic= [AGSGraphic graphicWithGeometry:pointToDraw symbol:myMarkerSymbol attributes:attributes];

[myGraphicsLayer addGraphic:myGraphic];

1 个答案:

答案 0 :(得分:0)

我也面临同样的问题。我已经查过了,

AGSPoint* gpsPoint = [[AGSPoint alloc] initWithX:gpsLocation.coordinate.longitude y:gpsLocation.coordinate.latitude spatialReference:[AGSSpatialReference wgs84SpatialReference]];

但它对我不起作用。我得到了link这个完全适合我的解决方案,你只需要将经度和纬度转换为映射点X和Y.这是代码,

//convert longitude and latitude to map point X Y
double mercatorX = loc.coordinate.longitude * 0.017453292519943295 * 6378137.0;
double a = loc.coordinate.latitude * 0.017453292519943295;
double mercatorY = 3189068.5 * log((1.0 + sin(a))/(1.0 - sin(a)));

AGSPoint *myMarkerPoint = [AGSPoint pointWithX:mercatorX y:mercatorY spatialReference:[AGSSpatialReference wgs84SpatialReference]];