Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 381
Hrushikesh Betai Avatar asked Jan 25 '12 05:01

Hrushikesh Betai


1 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.

like image 58
Satyam Avatar answered Sep 28 '22 07:09

Satyam