How to get the current location of the user in the simulator in iphone sdk?

I get the user location from this method

/*Region and Zoom*/ MKCoordinateRegion region; MKCoordinateSpan span; span.latitudeDelta=0.2; span.longitudeDelta=0.2; CLLocation *location1 = [locationManager location]; CLLocationCoordinate2D location = [location1 coordinate]; location.latitude = location.latitude; location.longitude = location.longitude; region.span=span; region.center = location; /*Geocoder Stuff*/ MKReverseGeocoder *geoCoder=[[MKReverseGeocoder alloc] initWithCoordinate:location]; geoCoder.delegate = self; [geoCoder start]; mapView.showsUserLocation = TRUE; [mapView setRegion:region animated:TRUE]; [mapView regionThatFits:region]; 

This works fine, but when I try to run this code in the simulator, it breaks at the point [mapView setRegion:region animated:TRUE]; , this suggests that it does not receive the latitude and longitude values. So, how can I do this code in the simulator perfectly.

I need to make this code run in the simulator, is this possible?

+4
source share
2 answers

On iOS5 Simulator, by default you will show your location in the USA. If you want to change this location, in the iOS Simulator menu, go to Debug → Location → Custom Location. There you can set the latitude and longitude and check the application accordingly. This works with mapkit as well as with CLLocationManager.

+13
source

try this way -

Go to the product-> Change Scheme-> Options-> select "Allow Placement"

This is not your exact location! But at least you can check if your code is working.

+10
source

Source: https://habr.com/ru/post/1392846/


All Articles