ios - 高德地图 有时候返回的地理位置比较慢
PHPz
PHPz 2017-04-18 09:50:51
0
1
1061

这个是高德地图的回调方法
-(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;
    }
}];
   

}

PHPz
PHPz

学习是最好的投资!

Antworte allen(1)
小葫芦

终于解决了
不需要这个方法
__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];
    }
};
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage