Maison > Questions et réponses > le corps du texte
这个是高德地图的回调方法
-(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;
}
}];
}
高洛峰2017-04-18 09:52:51
Enfin résolu
Pas besoin de cette méthode
__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];
}
};