最近用ios自带地图做了一个小应用,需要定位当前位置,但是每次启动应用的时候,就会发现它定位在大西洋,但是按一下左下角的定位按钮就又可以了,(住:定位按钮是我自己添加的一个方法。)请问这个有没有什么解决办法啊?


iOS 地图 定位
------解决方案--------------------
viewDidLoad中添加如下代码
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 10.0f;
[locationManager startUpdatingLocation];
viewcontroller实现代理CLLocationManagerDelegate。
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation
{
CLLocationCoordinate2D theCoordinate;
theCoordinate.latitude = newLocation.coordinate.latitude;
theCoordinate.longitude = newLocation.coordinate.longitude;
//[self.mmapView setCenterCoordinate:theCoordinate];
//设定显示范围
MKCoordinateSpan theSpan;
theSpan.latitudeDelta=0.1;
theSpan.longitudeDelta=0.1;
//设置地图显示的中心及范围
MKCoordinateRegion theRegion;
theRegion.center=theCoordinate;
theRegion.span=theSpan;
// 设置地图显示的类型及根据范围进行显示
[self.mmapView setRegion:theRegion];
}
试下这样可以实现你需要的功能不、
------解决方案--------------------
请问,这个需要钱申请嘛?还是直接拿来就可以用呢
------解决方案--------------------
楼主在西安啊!同是西安人 支持你哦