how to get user current location in simulator in iphone sdk?

I am getting 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 perfectly but when I try to run this code in simulator then it gets crashed at the point of [mapView setRegion:region animated:TRUE]; this tells it doesn't get the latitude and longitude values. So how can I make this code run in simulator perfectly.

I have to make this code run in simulator, is it possible?

Answers


On iOS5 Simulator by default you it will show some location in USA. If you want to change that location, in iOS Simulator menu, go to Debug -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly. This works with mapkit and also with CLLocationManager.


try this path-

Go to product->Edit Scheme->Options->select Allow Location simulation

it won't be your exact location! But at least you can verify your code is working.


Need Your Help

Linking a Text Box to a variable?

c# textbox

I would like to have direct access to the text inside a textbox on another form, so I added a public variable _txt to a form and added an event like so: