如何知道iPhone中的当前位置?

| 我是iPhone应用程序开发的新手,我需要代码用户的当前位置。我想使用地图套件在“我的应用”中显示他的位置。请告诉我该怎么做?     
已邀请:
您可以参考苹果的文档以获取此CLLocationmanager类参考。     
- (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];    
}
    
您需要告诉地图视图以显示用户的位置(默认情况下未启用)。将此添加到viewDidLoad中:
[mapView setShowsUserLocation:YES];
请注意,在模拟器中,用户位置始终是加利福尼亚州库比蒂诺,因此您可能看不到它,具体取决于地图的当前中心和缩放比例。     

要回复问题请先登录注册