- (void) plotPoints { //--- Add a sample point. ---// //--- First, set up a symbol for the point. ---// AGSSimpleMarkerSymbol *myMarkerSymbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol]; myMarkerSymbol.color = [UIColor blueColor]; //--- Now, create a point for the graphic to be drawn. ---// AGSPoint *myPoint = [AGSPoint pointWithX:-96.6477 y:33.0477 spatialReference:self.mapView.spatialReference]; //--- Create a graphic using the marker and point. ---// AGSGraphic *myGraphic = [AGSGraphic graphicWithGeometry:myPoint symbol:myMarkerSymbol attributes:nil]; //--- Add the graphic to the graphic layer. ---// [self.graphicsLayer addGraphic:myGraphic]; }
//convert longitude and latitude to map point X Y double mercatorX = longitude * 0.017453292519943295 * 6378137.0; double a = latitude * 0.017453292519943295; double mercatorY = 3189068.5 * log((1.0 + sin(a))/(1.0 - sin(a)));
Solved! Go to Solution.
float longitude = -96.6477; float latitude = 33.0477; AGSPoint *wgs84Point = [AGSPoint pointWithX:longitude y:latitude spatialReference:[AGSSpatialReference wgs84SpatialReference]]; //This example shows using GeometryEngine to project, but you can also AGSGeometryGeographicToWebMercator() function //See https://developers.arcgis.com/ios/api-reference/_a_g_s_geometry_8h.html#ac501960bbf7012239968ba9107935430 AGSGeometryEngine* ge = [AGSGeometryEngine defaultGeometryEngine]; AGSPoint* webmercatorPoint = [ge projectGeometry:wgs84Point toSpatialReference:[AGSSpatialReference webMercatorSpatialReference ]]; AGSGraphic *myGraphic = [AGSGraphic graphicWithGeometry:webmercatorPoint symbol:myMarkerSymbol attributes:nil]; ...
You can use AGSGeometryGeographicToWebMercator() function to cover WGS 1984 coordinate to web mercator. Also, you can use AGSGeometryEngine's projectGeometry:toSpatialReference: method to project geometries in different spatial reference.
Hope this helps!
Regards,
Nimesh
- (void) plotPoints { //--- Add a sample point. ---// //--- First, set up a symbol for the point. ---// AGSSimpleMarkerSymbol *myMarkerSymbol = [AGSSimpleMarkerSymbol simpleMarkerSymbol]; myMarkerSymbol.color = [UIColor greenColor]; //--- Sample lat/long to test with. ---// float longitude = -96.6477; float latitude = 33.0477; //--- Convert longitude and latitude to map point X Y ---// double mercatorX = longitude * 0.017453292519943295 * 6378137.0; double a = latitude * 0.017453292519943295; double mercatorY = 3189068.5 * log((1.0 + sin(a))/(1.0 - sin(a))); //--- Now, create a point for the graphic to be drawn. ---// AGSPoint *myPoint = [AGSPoint pointWithX:mercatorX y:mercatorY spatialReference:self.mapView.spatialReference]; //--- Create a graphic using the marker and point. ---// AGSGraphic *myGraphic = [AGSGraphic graphicWithGeometry:myPoint symbol:myMarkerSymbol attributes:nil]; //--- Add the graphic to the graphic layer. ---// [self.graphicsLayer addGraphic:myGraphic]; //--- Force a better initial view for testing. ---// AGSMutableEnvelope *extent = [self.graphicsLayer.fullEnvelope mutableCopy]; [extent expandByFactor:1.5]; [self.mapView zoomToEnvelope:extent animated:YES]; }
float longitude = -96.6477; float latitude = 33.0477; AGSPoint *wgs84Point = [AGSPoint pointWithX:longitude y:latitude spatialReference:[AGSSpatialReference wgs84SpatialReference]]; //This example shows using GeometryEngine to project, but you can also AGSGeometryGeographicToWebMercator() function //See https://developers.arcgis.com/ios/api-reference/_a_g_s_geometry_8h.html#ac501960bbf7012239968ba9107935430 AGSGeometryEngine* ge = [AGSGeometryEngine defaultGeometryEngine]; AGSPoint* webmercatorPoint = [ge projectGeometry:wgs84Point toSpatialReference:[AGSSpatialReference webMercatorSpatialReference ]]; AGSGraphic *myGraphic = [AGSGraphic graphicWithGeometry:webmercatorPoint symbol:myMarkerSymbol attributes:nil]; ...