all
I am new to arcgis for iOS, now I encounter a strange problem, and I have looked into other threads but haven't find any solutions.
I want to show a building whose longitude is 116.929167 and latitude is 34.727222 on my graphic layer. My base map layer is in a WGS84 spatial reference.
However, when I first tried the following code, it results in the point being misplaced. Note: the place is somewhere in Jangsu Province, China, but it was placed in Hunan Province, China.
//create an instance of a tiled map service layer
AGSTiledMapServiceLayer *tiledLayer = [[AGSTiledMapServiceLayer alloc] initWithURL:[NSURL URLWithString:kTiledMapServiceURL]];
//Add it to the map view
[self.mapView addMapLayer:tiledLayer withName:@"Tiled Layer"];
//release to avoid memory leaks
//set the callout delegate so we can display callouts
self.mapView.callout.delegate = self;
//add graphics layer for the graphics
self.graphicsLayer = [AGSGraphicsLayer graphicsLayer];
//add the graphics layer to the map
[self.mapView addMapLayer:self.graphicsLayer withName:@"Graphics Layer"];
//zoom to china
AGSEnvelope *chinaEnv = [AGSEnvelope envelopeWithXmin:78.0000000
ymin:0.4400000
xmax:156.0000000
ymax:75.0000000
spatialReference:[AGSSpatialReference wgs84SpatialReference]];
[self.mapView zoomToEnvelope:chinaEnv animated:YES];
self.mapView.callout.customView = nil;
self.mapView.callout.accessoryButtonHidden = YES;
double longitude = 116.929167;
double latitude = 34.727222;
AGSPoint *graphicPoint = [AGSPoint pointWithX:longitude y:latitude spatialReference:[AGSSpatialReference wgs84SpatialReference]];
[self.mapView.callout showCalloutAt:graphicPoint screenOffset:CGPointMake(0, 0) animated:YES];
Can anyone tell me why it cannot show the correct location and how to fix this problem? Thank you very much for your time and answers! Best Regards.
I am afraid that you have confused between WGS84 Web Mercator and WGS84.
so back to your question, I think your basemap is WGS84 Web Mercator. but your mappoint is wgs84SpatialReference. you have to project it.
wish this solves your problem.