这是我的代码......
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
location_updated = [locations lastObject];
NSLog(@"updated coordinate are %@",location_updated);
latitude1 = location_updated.coordinate.latitude;
longitude1 = location_updated.coordinate.longitude;
self.lblLat.text = [NSString stringWithFormat:@"%f",latitude1];
self.lblLon.text = [NSString stringWithFormat:@"%f",longitude1];
NSString *str = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?latlng=%f,%f&sensor=false",latitude1,longitude1];
url = [NSURL URLWithString:str];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
connection = [NSURLConnection connectionWithRequest:request delegate:self];
if (connection)
{
webData1 = [[NSMutableData alloc]init];
}
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(latitude1,longitude1);
marker.title = formattedAddress;
marker.icon = [UIImage imageNamed:@"m2.png"];
marker.map = mapView_;
marker.draggable = YES;
}
Run Code Online (Sandbox Code Playgroud)
这个方法多次调用,我不想......
问题:我似乎无法停止Core Location向我的应用/跟踪发送更新.
我在做什么:在我的viewWillAppear调用中self.locationManager,将其传递给一个方法,以显示用户在地图上的位置(实例MKMapView).重写getter以检查服务器的可用性,以查看是否已授权.如果是这样,它allocs/inits和startMonitoringSignificantLocationChanges和returns.
在viewDidDisappear,我打电话[self.locationManager stopUpdatingLocation].但我仍然可以在状态栏中看到位置图标.即使我通过双击主页按钮并关闭它来终止应用程序,图标仍然存在...即使在延长的时间(10分钟以上)之后.当我转到设置应用程序时,它告诉我我的应用程序仍在使用位置服务(紫色图标).
问题:我在这里错过了什么?为什么位置更新不会停止?
提前致谢.