一行代码显示你的位置
iOS中的MapKit集成了定位的功能,使用一行代码就可以在google地图上展示出自己当前的位置,代码如下:
-(IBAction) showLocation:(id) sender { if ([[btnShowLocation titleForState:UIControlStateNormal] isEqualToString:@"Show My Location"]) { [btnShowLocation setTitle:@"Hide My Location" forState:UIControlStateNormal]; mapView.showsUserLocation = YES; } else { [btnShowLocation setTitle:@"Show My Location" forState:UIControlStateNormal]; mapView.showsUserLocation = NO; } }
关键的代码就是:mapView.showUserLocation=YES.
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self; locationManager.desiredAccuracy = kCLLocationAccuracyBest;
locationManager.distanceFilter = 1000.0f;
locationManager.distanceFilter = kCLDistanceFilterNone;
[locationManager startUpdatingLocation];
[locationManager stopUpdatingLocation];
CLLocationDegrees latitude = theLocation.coordinate.latitude; CLLocationDegrees longitude = theLocation.coordinate.longitude;
CLLocationDistance altitude = theLocation.altitude;
总结:本文主要是讲解了如何在iOS设备google地图上展示自己的当前位置。