开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜