简体   繁体   中英

Drawing an AGSPoint on AGSMapView iOS

I integrated arcGis sdks to my iOS project but when tried to plot agsPoint to some point its always plotting to (0,0). I think its due to spatial reference

Thanks in advance

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

I am also facing the same problem. I have checked with,

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

But it was not worked for me. I got the solution on this link which perfectly works for me, you just need to convert longitude and latitude to map point X and Y. Here is the code,

//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]];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM