MKCoordinateRegion总是锁定在中心坐标0,0上?

时间:2012-11-10 07:33:00

标签: mkmapview mapkit

这有点奇怪,但我一直试图找到一个解决方案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);
}

NSLog for malocation.userlocation.coordinate在启动时始终为0。 我将它添加到viewDidLoad part&中的相同代码也没有区别

请帮助

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分: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];
}

就是那些人:)

相关问题