一行代碼顯示你的位置 git
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. ide
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地圖上展現本身的當前位置。 google