0

这有点奇怪,但我已经连续 2 天试图找到一个解决方案来设置地图区域,但似乎没有任何效果这是我的代码:

-(void)viewWillAppear:(BOOL)animated{
//[self step1locationupdate];
Maplocation.showsUserLocation=YES;

MKCoordinateRegion mapRegion;

    mapRegion.center.longitude=self.currentProduct.shop.longcoordinate;
mapRegion.center.latitude=self.currentProduct.shop.latcoordinate;

NSLog(@"The USer Location are :%f",mapRegion.center.latitude);

mapRegion.span.latitudeDelta= 2;
mapRegion.span.longitudeDelta= 2;

[Maplocation setRegion:mapRegion animated:YES];
NSLog(@"The USer Location are :%f %f",Maplocation.userLocation.coordinate.latitude,Maplocation.userLocation.coordinate.longitude);
}

启动时,malocation.userlocation.coordinate 的 NSLog 始终为 0。我已将其添加到 viewDidLoad 部分中的相同代码也没有区别

请帮助

4

2 回答 2

0

我认为您需要在开始使用 MKCoordinateRegion 之前对其进行初始化。像'MKCoordinateRegion mapRegion = MKMakeRegionWithCoordinates(......'

于 2012-11-11T01:46:24.890 回答
0

好吧,我已将上述方法保存在 (void) 方法中,然后在 viewWillAppear 方法的 5 秒后将其触发。

    -(void)viewWillAppear:(BOOL)animated{
    [self performSelector:@selector(updatecurrentLocation) withObject:nil afterDelay:5];
}
    -(void)updatecurrentLocation{

    Maplocation.showsUserLocation=YES;
    MKCoordinateRegion mapregion;
    mapregion.center=Maplocation.userLocation.coordinate;
    mapregion.span.latitudeDelta = 2;
    mapregion.span.longitudeDelta = 2;
    [Maplocation setRegion:mapregion animated: YES];
}

就是这样的人:)

于 2012-11-11T15:57:27.950 回答