I am using MKMapView on my application. i need to show current location on simulator.
is it possible. to show current location on simulator.
Simulator will not show user current location no matter whether it is iOS 6, 6.1 or iOS 7. To simulate location you can see here. If you want to show user current location then run your app in device or change simulator setting -
from the simulator's menu choose Debug > Location > Custom Location....
In the simulator, the user's current location is always in Cupertino, California.
If you're using Interface Builder to add your map view, simply check the "Shows User Location" check box in the Attributes Inspector for the map view. (Select the map view and type command-1
to display the attributes inspector.)
If you're adding or manipulating the map view programmatically, set the showsUserLocation property of the map view to YES
.
Update: It turns out that this is possible, just not using the built in map view functionality, and it doesn't always work.
Recent versions of the SDK (which have to run on Snow Leopard) can get the location of the machine the simulator is running on using CLLocationManager. You can then use this location to create an annotation to display on the map view. It won't behave like the built in "user's location indicator" (at least not without some work), but it will show the user's current location.
See this post for details of when this technique won't work.
See the "Related sample code" section of the CLLocationManager documentation for sample code that uses CLLocationManager and CLLocationManagerDelegate and then displays the user's location on a map view.
self.mapView.delegate = self;
self.mapView.showsUserLocation = YES;
This will show the current location in MkMapview
.
If you are using Interface Builder,In the Attributes Inspector , we have an option Behaviour
which has an option Show User Location
, on checking that option will also do the same.
If you are not able to see in simulator,
With CLLocationManager
also we can get the current location,
Import Corelocation
FrameWork to the project
In .h
file
#import <CoreLocation/CoreLocation.h>
@property (nonatomic, strong) CLLocationManager *locationManager;
@property (nonatomic, strong) CLLocation* currentLocation;
In .m
file
if ([CLLocationManager locationServicesEnabled] )
{
if (self.locationManager == nil )
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kDistanceFilter; //kCLDistanceFilterNone// kDistanceFilter;
}
[self.locationManager startUpdatingLocation];
}
The delegate function :
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
self.currentLocation = [locations lastObject];
// here we get the current location
}
Hope this answer may help you.