【发布时间】:2014-04-13 02:57:46
【问题描述】:
这是我的代码......
-(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;
}
这个方法被多次调用,我不想要.....
【问题讨论】:
-
那为什么要调用这个方法呢?
-
每五分钟更新一次位置。
-
当您第一次启动定位服务时,您可能会看到它被多次调用,并且位置越来越准确(例如,减少
horizontalAccuracy)。还要设置CLLocationManager属性distanceFilter和desiredAccuracy来控制调用频率。 -
Swift 3 版本接受的答案stackoverflow.com/a/43066729/7250862
标签: ios iphone cllocationmanager cllocation