0

好吧,这确实是一个愚蠢的问题和令人困惑的问题。我试图让地图跨越并专注于某个区域,所以我将位置设置为 Userlocation,它是完美的。

虽然当我保存用户位置并尝试在 viewDidLoad 中上传它们时,它不起作用。

    - (IBAction)GetcurrentLocation1:(id)sender{


    Maplocation.showsUserLocation=YES;
    MKCoordinateRegion mapRegion;
    mapRegion.center = Maplocation.userLocation.coordinate;
    NSLog(@"The USer Location are :%f %f",Maplocation.userLocation.coordinate.latitude,Maplocation.userLocation.coordinate.longitude);
    mapRegion.span.latitudeDelta = 0.2;
    mapRegion.span.longitudeDelta = 0.2;
    self.currentProduct.shop.longcoordinate=Maplocation.userLocation.coordinate.longitude;
    self.currentProduct.shop.latcoordinate=Maplocation.userLocation.coordinate.latitude;
    [Maplocation setRegion:mapRegion animated: YES];
}

    -(void)showtheuseronmap:(double)longtitude:(double)latitude{
        if(!annotation){
            annotation =[[MyAnotation alloc]initWithCoordinate:CLLocationCoordinate2DMake(latitude, longtitude) title:[self.currentProduct.shop shopname] subtitle:@"The shop is here"];
        }
        [Maplocation addAnnotation:annotation];
        MKCoordinateRegion mapRegion;
        CLLocationCoordinate2D locationsh=CLLocationCoordinate2DMake(latitude, longtitude);
        mapRegion.center=locationsh;
        NSLog(@"The USer Location are :%f",mapRegion.center.latitude);
        mapRegion.span.latitudeDelta= 0.2;
        mapRegion.span.longitudeDelta= 0.2;
        [Maplocation setRegion:mapRegion animated:YES];

        //Maplocation.showsUserLocation=YES;





    }

在 viewDidLoad

[self showtheuseronmap:self.currentProduct.shop.longcoordinate :self.currentProduct.shop.latcoordinate];

在 NSLog 中,我可以正确看到坐标。

我真的很困惑,我不知道这是怎么回事?

4

0 回答 0