为用户位置生成地图区域而不是自定义位置

时间:2012-11-06 01:05:11

标签: mkmapview core-location mkcoordinateregion mkcoordinatespan

这真的是一个愚蠢的问题&混乱。 我试图让地图跨越&专注于某个区域,所以我将位置设置为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中,我可以正确地看到坐标。

我真的很困惑,我不知道这会怎么样?

0 个答案:

没有答案