iphone - How to stop multiple times method calling of didUpdateLocations() in ios -
this code......
-(void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations { location_updated = [locations lastobject]; nslog(@"updated coordinate %@",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; }
this method call multiple times don't want.....
add restriction there. timespan between locations , accuracy
-(void)locationmanager:(cllocationmanager *)manager didupdatelocations:(nsarray *)locations { cllocation *newlocation = locations.lastobject; nstimeinterval locationage = -[newlocation.timestamp timeintervalsincenow]; if (locationage > 5.0) return; if (newlocation.horizontalaccuracy < 0) return; // needed filter cached , old locations //nslog(@"location updated = %@", newlocation); cllocation *loc1 = [[cllocation alloc] initwithlatitude:_currentlocation.coordinate.latitude longitude:_currentlocation.coordinate.longitude]; cllocation *loc2 = [[cllocation alloc] initwithlatitude:newlocation.coordinate.latitude longitude:newlocation.coordinate.longitude]; double distance = [loc1 distancefromlocation:loc2]; _currentlocation = newlocation; if(distance > 20) { //significant location update } //location updated }
Comments
Post a Comment