- Get link
- X
- Other Apps
- Get link
- X
- Other Apps
MapLatitudeLogitude.h
#import <UIKit/UIKit.h>
#import <CoreLocation/CoreLocation.h>
#import "MapKit/MapKit.h"
@interface MapLatitudeLongitude : UIViewController <CLLocationManagerDelegate, MKMapViewDelegate>
@property (weak, nonatomic) IBOutlet UITextField *txt_latitude;
@property (weak, nonatomic) IBOutlet UITextField *txt_longitude;
@property (weak, nonatomic) IBOutlet MKMapView *mkMapView;
- (IBAction)bt_zoomin:(id)sender;
- (IBAction)bt_changeType:(id)sender;
- (IBAction)bt_showlatitude:(id)sender;
MapLatitudeLogitude.m
#import "MapLatitudeLongitude.h"
@interface MapLatitudeLongitude ()
{
NSString *cur_lat;
NSString *cur_long;
}
@end
@implementation MapLatitudeLongitude
CLLocationManager *locationManager;
- (void)viewDidLoad {
[super viewDidLoad];
locationManager=[[CLLocationManager alloc]init];
_mkMapView.showsUserLocation=YES;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/**
Zoom Map View
*/
- (IBAction)bt_zoomin:(id)sender {
MKUserLocation *loc=_mkMapView.userLocation;
MKCoordinateRegion reg=MKCoordinateRegionMakeWithDistance(loc.location.coordinate, 2000, 2000);
[_mkMapView setRegion:reg animated:YES];
}
/**
Change Map view style
*/
- (IBAction)bt_changeType:(id)sender {
if(_mkMapView.mapType==MKMapTypeSatellite)
_mkMapView.mapType=MKMapTypeStandard;
else
_mkMapView.mapType=MKMapTypeSatellite;
}
- (IBAction)bt_showlatitude:(id)sender {
locationManager.delegate=self;
locationManager.desiredAccuracy=kCLLocationAccuracyBest;
[locationManager requestWhenInUseAuthorization];
[locationManager startUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation{
CLLocation *clllocation=newLocation;
NSLog(@"%@",newLocation);
if(clllocation!=nil){
cur_lat=[NSString stringWithFormat:@"%.8f",clllocation.coordinate.latitude];
cur_long=[NSString stringWithFormat:@"%.8f",clllocation.coordinate.longitude];
_txt_latitude.text=cur_lat;
_txt_longitude.text=cur_long;
CLLocationCoordinate2D location;
location.latitude=[cur_lat doubleValue];
location.longitude=[cur_long doubleValue];
MKCoordinateRegion region=MKCoordinateRegionMakeWithDistance(location, 2000, 2000);
[_mkMapView setRegion:region animated:YES];
}
}
Comments
Post a Comment