iPhone Map


Java代码
  1. #import <UIKit/UIKit.h>  
  2. #import <CoreLocation/CoreLocation.h>  
  3. #import <MapKit/MapKit.h>  
  4. @interface LBSViewController : UIViewController  
  5.     <CLLocationManagerDelegate> {  
  6.     IBOutlet UITextField *accuracyTextField;  
  7.     IBOutlet UITextField *latitudeTextField;  
  8.     IBOutlet UITextField *longitudeTextField;  
  9.     CLLocationManager *lm;  
  10.     
  11.     MKMapView *mapView;  
  12. }  
  13. @property (retain, nonatomic) UITextField *accuracyTextField;  
  14. @property (retain, nonatomic) UITextField *latitudeTextField;  
  15. @property (retain, nonatomic) UITextField *longitudeTextField;  
  16.   
  17. -(IBAction) btnViewMap: (id) sender;  
  18.   
  19. @end  
Java代码
  1. -(IBAction) btnViewMap: (id) sender {  
  2.     [self.view addSubview:mapView];  
  3. }  
  4. - (void) viewDidLoad {  
  5.     lm = [[CLLocationManager alloc] init];  
  6.     lm.delegate = self;  
  7.     lm.desiredAccuracy = kCLLocationAccuracyBest;  
  8.     lm.distanceFilter = 1000.0f;  
  9.     [lm startUpdatingLocation];  
  10.       
  11.     mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];  
  12.     mapView.mapType = MKMapTypeHybrid;  
  13. }  
  14. - (void) locationManager: (CLLocationManager *) manager  
  15.     didUpdateToLocation: (CLLocation *) newLocation  
  16.     fromLocation: (CLLocation *) oldLocation{  
  17.     NSString *lat = [[NSString alloc] initWithFormat:@"%g",  
  18.         newLocation.coordinate.latitude];  
  19.     latitudeTextField.text = lat;  
  20.       
  21.     NSString *lng = [[NSString alloc] initWithFormat:@"%g",  
  22.         newLocation.coordinate.longitude];  
  23.     longitudeTextField.text = lng;  
  24.       
  25.     NSString *acc = [[NSString alloc] initWithFormat:@"%g",  
  26.         newLocation.horizontalAccuracy];  
  27.     accuracyTextField.text = acc;      
  28.       
  29.     [acc release];  
  30.     [lat release];  
  31.     [lng release];  
  32.       
  33.     MKCoordinateSpan span;  
  34.     span.latitudeDelta=.005;  
  35.     span.longitudeDelta=.005;  
  36.       
  37.     MKCoordinateRegion region;  
  38.     region.center = newLocation.coordinate;  
  39.     region.span=span;  
  40.       
  41.     [mapView setRegion:region animated:TRUE];  
  42. }  
  43. - (void) dealloc{  
  44.     [mapView release];  
  45.     [lm release];  
  46.     [latitudeTextField release];  
  47.     [longitudeTextField release];  
  48.     [accuracyTextField release];  
  49.     [super dealloc];  
  50. }  


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值