How to know current Location in iPhone?
I am new to iphone App development, I Need code Current Locatio开发者_如何学编程n of the user. I want show his Location in My App using map Kit. Please tell me how to do that?
You may refer the apple's document for this CLLocationmanager class reference
- (IBAction) showCurrentLocation{
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.007;
span.longitudeDelta=0.007;
CLLocationCoordinate2D location = [[[mapview userLocation] location] coordinate];
//NSLog(@"Location found from Map: %f %f",location.latitude,location.longitude);
region.span=span;
region.center=location;
[mapview setRegion:region animated:TRUE];
[mapview regionThatFits:region];
}
You need to tell the map view to show the user's location (it's not on by default). Add this to the viewDidLoad:
[mapView setShowsUserLocation:YES];
Note that in the simulator, the user location is always Cupertino, CA so you might not see it depending on the map's current center and zoom.
精彩评论