warning: Semantic Issue: Class method '+projectGeometry:toSpatialReference:' not found (return type defaults to 'id') 'AGSGeometryEngine' may not respond to '+projectGeometry:toSpatialReference:'
AGSPoint *myPointReprojected; myPointReprojected = [AGSGeometryEngine projectGeometry:myPoint toSpatialReference:[AGSSpatialReference webMercatorSpatialReference]];
myPointReprojected = [[AGSGeometryEngine defaultGeometryEngine] projectGeometry:myPoint toSpatialReference:[AGSSpatialReference webMercatorSpatialReference]];
AGSGeometryEngine *ge = [AGSGeometryEngine defaultGeometryEngine]; myPointReprojected = [ge projectGeometry:myPoint toSpatialReference:[AGSSpatialReference webMercatorSpatialReference]];
- (void)locator:(AGSLocator *)locator operation:(NSOperation *)op didFindLocationsForAddress:(NSArray *)candidates{ //check and see if we didn't get any results if (candidates == nil || [candidates count] == 0) { //show alert if we didn't get results UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Informazione" message:@"Nessun risultato trovato" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } else { //use these to calculate extent of results double xmin = DBL_MAX; double ymin = DBL_MAX; double xmax = -DBL_MAX; double ymax = -DBL_MAX; //create the callout template, used when the user displays the callout self.calloutTemplate = [[[AGSCalloutTemplate alloc]init] autorelease]; //loop through all candidates/results and add to graphics layer for (int i=0; i<[candidates count]; i++) { AGSAddressCandidate *addressCandidate = (AGSAddressCandidate *)[candidates objectAtIndex:i]; //get the location from the candidate AGSPoint *pt = addressCandidate.location; //accumulate the min/max if (pt.x < xmin) xmin = pt.x; if (pt.x > xmax) xmax = pt.x; if (pt.y < ymin) ymin = pt.y; if (pt.y > ymax) ymax = pt.y; AGSGeometry *myPointReprojected; myPointReprojected = [[AGSGeometryEngine defaultGeometryEngine] projectGeometry:pt toSpatialReference:[AGSSpatialReference spatialReferenceWithWKID:102100]]; //create a marker symbol to use in our graphic AGSPictureMarkerSymbol *marker = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:@"BluePushpin.png"]; marker.xoffset = 9; marker.yoffset = -16; marker.hotspot = CGPointMake(-9, -11); //set the text and detail text based on 'Name' and 'Descr' fields in the attributes self.calloutTemplate.titleTemplate = self.searchBar.text; //self.calloutTemplate.detailTemplate = @"${Descr}"; //create the graphic AGSGraphic *graphic = [[AGSGraphic alloc] initWithGeometry: pt symbol:marker attributes:[[addressCandidate.attributes mutableCopy] autorelease] infoTemplateDelegate:self.calloutTemplate]; //add the graphic to the graphics layer [self.graphicsLayer addGraphic:graphic]; if ([candidates count] == 1) { //we have one result, center at that point [self.mapView5 centerAtPoint:pt animated:NO]; // set the width of the callout self.mapView5.callout.width = 250; //show the callout [self.mapView5 showCalloutAtPoint:(AGSPoint *)graphic.geometry forGraphic:graphic animated:YES]; } //release the graphic bb [graphic release]; } //if we have more than one result, zoom to the extent of all results int nCount = [candidates count]; if (nCount > 1) { AGSMutableEnvelope *extent = [AGSMutableEnvelope envelopeWithXmin:xmin ymin:ymin xmax:xmax ymax:ymax spatialReference:self.mapView5.spatialReference]; [extent expandByFactor:1.5]; [self.mapView5 zoomToEnvelope:extent animated:YES]; } } //since we've added graphics, make sure to redraw [self.graphicsLayer dataChanged]; }
If you are using this (http://tasks.arcgis.com/ArcGIS/rest/services/WorldLocator/GeocodeServer) locator service to find addresses then you don't need to project the result geometries. Just use AGSLocator's locationsForAddress:returnFields:outSpatialReference: method and set the desired outSpatialReference.
Hope this helps!
Regards,
Nimesh
Nimesh you are a great
It does work, but I have another question. I can not do the zoom on the address searched. Any suggestions?