AGSPoint *pt = addressCandidate.location; AGSMutablePoint *newPoint = [AGSMutablePoint pointWithX:pt.x y:pt.y spatialReference:self.mapView.spatialReference];
[self.locator locationsForAddress:addresses returnFields:outFields outSpatialReference:self.mapView.spatialReference];
Hmm, not sure why you're still having problems.Can you print the point to the console and see if the x,y, and spatial ref values look okay. Use NSLog(@Point: %@", point);
2010-10-31 17:05:26.223 iWatch[470:207] Point: AGSPoint: x = -1.785897, y = 43.031819, spatial reference: [AGSSpatialReference: wkid = 102100, wkt = null]
- (void)geometryServiceTask:(AGSGeometryServiceTask *)geometryServiceTask operation:(NSOperation *)op didReturnProjectedGeometries:(NSArray *)newGeometry
Ok. I am stumped. I'm not sure why your 931 Geocode Service does not give you back the correctly projected results.For using the Geometry Service, your input geometries must have a valid spatial reference. Without this info, the geometry service cannot truly project your geometries.If you're still having problems, I can take a look at your code to see what might be going on.
AGSSpatialReference* outSR = [AGSSpatialReference spatialReferenceWithWKID:31259 WKT:nil]; [self.locator locationsForAddress:addresses returnFields:outFields outSpatialReference:outSR];
Candidate : AGSPoint: x = 15.441723, y = 47.067916, spatial reference: [(null)]
[self.gst projectGeometries:self.geometryArray:outSR];
[self.gst projectGeometries:self.geometryArray toSpatialReference:outSR];
- (void)geometryServiceTask:(AGSGeometryServiceTask *)geometryServiceTask operation:(NSOperation *)op didReturnProjectedGeometries:(NSArray *)projectedGeometries { NSLog(@didReturnProjectedGeometries); } - (void)geometryServiceTask:(AGSGeometryServiceTask *)geometryServiceTask operation:(NSOperation*)op didFailProjectWithError:(NSError *)error { NSLog(@didFailProjectWithError); }
below formula converts 4326 latitude to 102100 latitude+ (double)toWebMercatorY:(double)latitude{ double rad = latitude * 0.0174532; double fsin = sin(rad); double y = 6378137 / 2.0 * log((1.0 + fsin) / (1.0 - fsin)); return y;}below formula converts 4326 longitude to 102100 longitude+ (double)toWebMercatorX:(double)longitude{ double x = longitude * 0.017453292519943 * 6378137; return x;}See my attachment , it contains a utility mercator convertor . You can simply import the class in your project and call the above static methods on itI have tried it with location manager and it works!!!Regards,Harikant Jammi
- (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; //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; //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]; }
This was very helpful for me and solved my problem of converting between coordinate systems.
Thank you.
Hi,
These methods are not accessible in runtime SDK 100.x. how can i achieve this?
Regards,
Look at AGSGeometryEngine.projectGeometry().
Yes i found that. Lot of stuffs in that class. Thanks Nick.
Přihlášení členové mohou přispívat, sledovat aktualizace a další. Jste tu noví? Zaregistrujte si bezplatný účet.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.