el map no pudo mostrar mi location

Quiero mostrar un map y mostrar la location. Mi código funciona bien, pero la location no se puede mostrar en el map. No se como hacerlo.

Bueno, aquí están mis classs:

ViewController.h

@interface ViewController : UIViewController<AGSMapViewLayerDelegate,CLLocationManagerDelegate> { AGSMapView *_mapView; AGSGraphicsLayer *_graphicsLayer; AGSTiledMapServiceLayer *_tiledLayer; CLLocationManager *locationManager; CLLocation *startingPoint; } @property (nonatomic,retain) IBOutlet AGSMapView *mapView; @property (nonatomic, retain) AGSTiledMapServiceLayer *tiledLayer; @property (nonatomic, retain) CLLocationManager *locationManager; @property (nonatomic, retain) AGSGraphicsLayer *graphicsLayer; @property (nonatomic, retain) CLLocation *startingPoint; 

ViewController.m

 @interface ViewController() @end @implementation ViewController @synthesize mapView = _mapView; @synthesize graphicsLayer = _graphicsLayer; @synthesize tiledLayer = _tiledLayer; @synthesize locationManager; @synthesize startingPoint; - (void)viewDidLoad { [super viewDidLoad]; self.mapView.layerDelegate =self; self.graphicsLayer = [AGSGraphicsLayer graphicsLayer]; [self.mapView addMapLayer:self.graphicsLayer withName:@"graphicsLayer"]; self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; // send loc updates to myself self.locationManager.distanceFilter = 1000.0f; // 1 kilometer self.locationManager.desinetworkingAccuracy = kCLLocationAccuracyKilometer; } - (void)mapViewDidLoad:(AGSMapView *)mapView{ [self.locationManager startUpdatingLocation]; //启用位置监控} - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ self.startingPoint = [locations lastObject]; [self.locationManager stopUpdatingLocation]; //获取位置信息CGPoint coord; coord.x = startingPoint.coordinate.longitude; coord.y = startingPoint.coordinate.latitude; //将坐标用AGSPoint来表示AGSPoint *mappoint = [[AGSPoint alloc]initWithX:coord.xy:coord.y spatialReference:nil]; //[self.graphicsLayer removeAllGraphics]; AGSPictureMarkerSymbol *pt; pt = [AGSPictureMarkerSymbol pictureMarkerSymbolWithImageNamed:@"LocationDisplay.png"]; AGSGraphic *LocationDisplay = [[AGSGraphic alloc] initWithGeometry:mappoint symbol:pt attributes:nil infoTemplateDelegate:nil]; // 添加要素到GraphicsLayer [self.graphicsLayer addGraphic:LocationDisplay]; [self.graphicsLayer refresh]; //漫游到指定级别[self.mapView centerAtPoint:mappoint animated:YES]; int levelToZoomTo = 12; AGSLOD* lod = [self.tiledLayer.mapServiceInfo.tileInfo.lods objectAtIndex:levelToZoomTo]; float zoomFactor = lod.resolution/self.mapView.resolution; AGSMutableEnvelope *newEnv = [AGSMutableEnvelope envelopeWithXmin:self.mapView.visibleAreaEnvelope.xmin ymin:self.mapView.visibleAreaEnvelope.ymin xmax:self.mapView.visibleAreaEnvelope.xmax ymax:self.mapView.visibleAreaEnvelope.ymax spatialReference:self.mapView.spatialReference]; [newEnv expandByFactor:zoomFactor]; [self.mapView zoomToEnvelope:newEnv animated:YES]; } 

Debe proporcionar una reference espacial cuando cree el punto AGSP desde las coorderadas CLLocation. Use [AGSSpatialReference wgs84SpatialReference]

Si el map no utiliza la reference espacial WGS84, entonces debe reproyectar el punto a la reference espacial del map antes de agregarlo al map utilizando el motor de geometry.

O

puede usar la propiedad locationDisplay integrada en AGSMapView, configurando mapView.locationDisplay.startDataSource para mostrar su location actual.

Consulte los documentos para AGSMapView

 func mapViewDidLoad(mapView: AGSMapView!) { //do something now that the map is loaded //for example, show the current location on the map mapView.locationDisplay.startDataSource() } 

Intente configurar mapview.showUserLocation = YES ; o configurarlo en XIB