0

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?

Craig
  • 8,093
  • 8
  • 42
  • 74
TALAA
  • 6,184
  • 1
  • 13
  • 21
  • In viewDidLoad, have you checked that the `self.currentProduct.shop.longcoordinate` has the right value for you to pass to `showtheuseronmap`? – Craig Nov 06 '12 at 18:15
  • Yes it Has the Right Value , Even if i fix it to a constant value , although i am suspecting that it hasnt the right format , i read somewhere that the Coordinates is better to keep them as Double – TALAA Nov 06 '12 at 22:32
  • well the Problem is i have 2 Maps in 2 Different ViewController, the First where i have the problem the user.location.coordinate.longitude & latitude are always 0 0. On the Other hand in the other view controller it shows perfectly from the start . – TALAA Nov 08 '12 at 22:57

0 Answers0