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

上記のメソッドを(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 に答える
0

使用を開始する前に MKCoordinateRegion を初期化する必要があると思います。「MKCoordinateRegion mapRegion = MKMakeRegionWithCoordinates(......」のようなもの

于 2012-11-11T01:46:24.890 に答える