您的位置:首页 > 其它

iPhone Map

2012-07-16 21:24 274 查看
Java代码

#import <UIKit/UIKit.h>

#import <CoreLocation/CoreLocation.h>

#import <MapKit/MapKit.h>

@interface LBSViewController : UIViewController

<CLLocationManagerDelegate> {

IBOutlet UITextField *accuracyTextField;

IBOutlet UITextField *latitudeTextField;

IBOutlet UITextField *longitudeTextField;

CLLocationManager *lm;

MKMapView *mapView;

}

@property (retain, nonatomic) UITextField *accuracyTextField;

@property (retain, nonatomic) UITextField *latitudeTextField;

@property (retain, nonatomic) UITextField *longitudeTextField;

-(IBAction) btnViewMap: (id) sender;

@end

Java代码

-(IBAction) btnViewMap: (id) sender {

[self.view addSubview:mapView];

}

- (void) viewDidLoad {

lm = [[CLLocationManager alloc] init];

lm.delegate = self;

lm.desiredAccuracy = kCLLocationAccuracyBest;

lm.distanceFilter = 1000.0f;

[lm startUpdatingLocation];

mapView = [[MKMapView alloc] initWithFrame:self.view.bounds];

mapView.mapType = MKMapTypeHybrid;

}

- (void) locationManager: (CLLocationManager *) manager

didUpdateToLocation: (CLLocation *) newLocation

fromLocation: (CLLocation *) oldLocation{

NSString *lat = [[NSString alloc] initWithFormat:@"%g",

newLocation.coordinate.latitude];

latitudeTextField.text = lat;

NSString *lng = [[NSString alloc] initWithFormat:@"%g",

newLocation.coordinate.longitude];

longitudeTextField.text = lng;

NSString *acc = [[NSString alloc] initWithFormat:@"%g",

newLocation.horizontalAccuracy];

accuracyTextField.text = acc;

[acc release];

[lat release];

[lng release];

MKCoordinateSpan span;

span.latitudeDelta=.005;

span.longitudeDelta=.005;

MKCoordinateRegion region;

region.center = newLocation.coordinate;

region.span=span;

[mapView setRegion:region animated:TRUE];

}

- (void) dealloc{

[mapView release];

[lm release];

[latitudeTextField release];

[longitudeTextField release];

[accuracyTextField release];

[super dealloc];

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: