搜索

首页  >  问答  >  正文

ios - 高德地图 有时候返回的地理位置比较慢

这个是高德地图的回调方法
-(void)mapView:(MAMapView )mapView didUpdateUserLocation:(MAUserLocation )userLocation
updatingLocation:(BOOL)updatingLocation
{

if(updatingLocation)
{
        self.lat = userLocation.coordinate.latitude;
        self.lon = userLocation.coordinate.longitude;

}
[self.locationManager requestLocationWithReGeocode:YES completionBlock:^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error) {
    
    if (regeocode)
    {
        // NSLog(@"reGeocode:%@%@",regeocode, regeocode.formattedAddress);//地理位置
        formattedAddress =regeocode.formattedAddress;
        NSString *str = regeocode.number;
        NSString *address = [regeocode.street stringByAppendingString:str];
        label2.text = address;
    }
}];
   

}

PHPzPHPz2771 天前1064

全部回复(1)我来回复

  • 高洛峰

    高洛峰2017-04-18 09:52:51

    终于解决了
    不需要这个方法
    __weak WaiQinqiandaoViewController *weakSelf = self;

    self.completionBlock = ^(CLLocation *location, AMapLocationReGeocode *regeocode, NSError *error)
    {
        if (error)
        {
            NSLog(@"locError:{%ld - %@};", (long)error.code, error.localizedDescription);
            
            //如果为定位失败的error,则不进行annotation的添加
            if (error.code == AMapLocationErrorLocateFailed)
            {
                return;
            }
        }
        //得到定位信息,添加annotation
        if (location)
        {
            NSLog(@"++++++++%f---%f--%@",location.coordinate.latitude,location.coordinate.longitude,regeocode.formattedAddress);
           weakSelf.lat = location.coordinate.latitude;
           weakSelf.lon = location.coordinate.longitude;
            MAPointAnnotation *annotation = [[MAPointAnnotation alloc] init];
            [annotation setCoordinate:location.coordinate];
            
            if (regeocode)
            {
                NSLog(@"<><><>>>%@",regeocode.formattedAddress);
                        formattedAddress =regeocode.POIName;
                        NSString *str = regeocode.number;
                        NSString *address = [regeocode.street stringByAppendingString:str];
                        label2.text = regeocode.AOIName;
                
                [[NSUserDefaults standardUserDefaults] setObject:regeocode.AOIName forKey:@"AOIName"];
                
                
                        NSLog(@"请求到的地址:%@",formattedAddress);
                        [_hudview removeFromSuperview];
                        [MBProgressHUD hide];
            }
            else
            {
                [annotation setTitle:[NSString stringWithFormat:@"lat:%f;lon:%f;", location.coordinate.latitude, location.coordinate.longitude]];
                [annotation setSubtitle:[NSString stringWithFormat:@"accuracy:%.2fm", location.horizontalAccuracy]];
            }
            
            WaiQinqiandaoViewController *strongSelf = weakSelf;
            [strongSelf addAnnotationToMapView:annotation];
        }
    };
    

    回复
    0
  • 取消回复