0

I cannot get my current location in iphone simulator. I set custom location to latitude and longitude to Egypt but doesn't get current location.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    //Make this controller the delegate for the map view.
    self.MapView.delegate = self;     

    // Ensure that you can view your own location in the map view.
    [self.MapView setShowsUserLocation:YES];



    //Instantiate a location object.
    locationManager = [[CLLocationManager alloc] init];
    [locationManager startUpdatingLocation];

    //Make this controller the delegate for the location manager.
    [locationManager setDelegate:self];

    //Set some parameters for the location object.
    [locationManager setDistanceFilter:kCLDistanceFilterNone];
    [locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
}

and this is delegate :

#pragma mark - MKMapViewDelegate methods.

- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views 
{    
    MKCoordinateRegion region;
    region = MKCoordinateRegionMakeWithDistance(locationManager.location.coordinate,2000,2000);


    [mv setRegion:region animated:YES];
}

Please any one help me.

2 Answers 2

3

What's the problem exactly? Not getting a userLocation where you're supposed to have or not moving the map region to the right place?

If it's the first, it is mostly a tools issue, not a code issue:

If your location is in a gpx file inside your project you should be able to start at it by editing Scheme / Options / Allow Location Simulation / and choose your default Location

Scheme Edition for starting at a specific place

And you should have a DemoStart.gpx file in your project that looks like:

<?xml version="1.0"?>
<gpx version="1.1" creator="Xcode">
    <wpt lat="20.88072" lon="10.67429">
        <name>Demo Starting Location</name>
    </wpt>
</gpx>

(Sorry, I'm too lazy to find Egypt's exact coordinates).

2
  • my iPhone Simulator version 5.0 where can i find this window ? Oct 23, 2012 at 11:58
  • In Xcode (not the simulator) you can Edit Scheme by clicking on the two part drop down list in the top left of the window. Or you can press the locations services icon near the bottom of the screen (the arrow next to the skip, step into, step out of)
    – Craig
    Oct 24, 2012 at 7:51
0

You must first be sure your CLLocationManager updates his location to yours. To do that, set the view controller as the CLLocationManager's delegate, you already did so, and save this location. Try calling startUpdatingLocation after you finished doing all the setup and also set showsUserLocation to YES.

- (void)locationManager:(CLLocationManager *)manager

     didUpdateLocations:(NSArray *)locations {

    // If it's a relatively recent event, turn off updates to save power

    CLLocation* myLocation = [locations lastObject];
}

Be sure you are testing this on iOS Simulator Version >= 5.1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.