- #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
- -(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];
- }