Map Region is Spaned for Userlocation not for Custom Location

149 views Asked by At

Well it is really a silly question & confusing. I am trying to get the map to span & focus on certain region , so I set the location as Userlocation, it is perfect.

Although when I save the user location & try to upload them in viewDidLoad, it doesn't work.

    - (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;





    }

in viewDidLoad

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

in NSLog , I can see the coordinates correctly.

I am really confused, I don't know how this can happen?

0

There are 0 answers