मेरे पास एक ऐसा ऐप है जो डिवाइस के जीपीएस और उस जानकारी से आता है जो इसके बारे में आता है। यह महत्वपूर्ण है कि स्थान डेटा सटीक और अद्यतित हो। मुझे पता है कि डिवाइस अपने जीपीएस और जीपीएस की सीमाओं से सीमित है, लेकिन मैं सोच रहा था कि आईफोन जीपीएस के प्रदर्शन को विशेष रूप से गति क्षेत्र में बदलने या सुधारने के लिए मैं कुछ भी कर सकता हूं। चूंकि स्थान अपडेट डिवाइस के रीयल-टाइम स्थान के पीछे लगभग 3-5 सेकंड पीछे रहता है, इसलिए स्थान प्रबंधक द्वारा रिपोर्ट की गई वेग भी वास्तविक समय मान के पीछे है। मेरे मामले में, यह बस बहुत लंबा है। मैं समझता हूं कि ऐसा कुछ भी नहीं हो सकता है जो मैं कर सकता हूं, लेकिन क्या किसी को आईफोन जीपीएस की प्रतिक्रिया में सुधार करने में कोई सफलता मिली है? हर छोटी बिट एक फर्क पड़ता है।CLLocationManager उत्तरदायित्व
संपादित करें 1:
मेरे स्थान प्रबंधक, एक सिंगलटन वर्ग के अंदर है के रूप में एप्पल सिफारिश की।
अंदर SingletonDataController.m:
static CLLocationManager* locationManager;
locationManager = [CLLocationManager new];
locationManager.distanceFilter = kCLDistanceFilterNone;
locationManager.headingFilter = kCLHeadingFilterNone;
if(([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) || ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateFull)) {
locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
} else {
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
[sharedSingleton setLocationManager:locationManager];
[locationManager release];
अंदर MapView.m (जहां स्थान प्रबंधक वास्तव में प्रयोग किया जाता है):
- (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil {
//setup
[SingletonDataController sharedSingleton].locationManager.delegate = self;
//more setup
}
- (void)batteryChanged {
if(([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging) || ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateFull)) {
[SingletonDataController sharedSingleton].locationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
} else {
[SingletonDataController sharedSingleton].locationManager.desiredAccuracy = kCLLocationAccuracyBest;
}
}
- (void)viewDidLoad {
//setup
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(batteryChanged)
name:UIDeviceBatteryStateDidChangeNotification
object:nil];
//other setup
}
डेटा से निपटने locationManager:didUpdateToLocation:fromLocation:
अंदर होता है। मुझे विश्वास नहीं है कि यहां अक्षमता अंतराल का कारण है।
locationManager:didUpdateToLocation:fromLocation:
कॉल यूआई अद्यतन करने के लिए इस विधि:
- (void)setLabels:(CLLocation*)newLocation fromOldLocation:(CLLocation*)oldLocation {
//set speed label
if(iterations > 0) {
if(currentSpeed > keyStopSpeedFilter) {
if(isFollowing) {
[mapViewGlobal setRegion:MKCoordinateRegionMake([newLocation coordinate], mapViewGlobal.region.span)];
}
NSString* currentSpeedString;
if(isCustomary) {
currentSpeedString = [[NSString alloc] initWithFormat:@"%.1f miles per hour", (currentSpeed * 2.23693629f)];
} else {
currentSpeedString = [[NSString alloc] initWithFormat:@"%.1f km per hour", (currentSpeed * 3.6f)];
}
[speedLabel setText:currentSpeedString];
[currentSpeedString release];
} else {
speedLabel.text = @"Not moving";
}
}
//set average speed label
if(iterations > 4 && movementIterations > 2) {
NSString* averageSpeedString;
if(isCustomary) {
averageSpeedString = [[NSString alloc] initWithFormat:@"%.1f miles per hour", (float)((speedAverages/(long double)movementIterations) * 2.23693629f)];
} else {
averageSpeedString = [[NSString alloc] initWithFormat:@"%.1f km per hour", (float)((speedAverages/(long double)movementIterations) * 3.6f)];
}
[averageSpeedLabel setText:averageSpeedString];
[averageSpeedString release];
}
//set elapsed time label
NSInteger seconds = [[NSDate date] timeIntervalSinceDate:dataObject.locationManagerStartDate];
NSInteger minutes = seconds/60;
NSInteger hours = minutes/60;
//get remainder
seconds %= 60;
NSString* timeString;
NSString* secondsString;
NSString* minutesString;
NSString* hoursString;
if((seconds % 60) < 10) {
secondsString = [[NSString alloc] initWithFormat:@"0%i", seconds];
} else {
secondsString = [[NSString alloc] initWithFormat:@"%i", seconds];
}
if((minutes % 60) < 10) {
minutesString = [[NSString alloc] initWithFormat:@"0%i", minutes];
} else {
minutesString = [[NSString alloc] initWithFormat:@"%i", minutes];
}
if((hours % 60) < 10) {
hoursString = [[NSString alloc] initWithFormat:@"0%i", hours];
} else {
hoursString = [[NSString alloc] initWithFormat:@"%i", hours];
}
timeString = [[NSString alloc] initWithFormat:@"%@:%@:%@", hoursString, minutesString, secondsString];
[elapsedTimeLabel setText:timeString];
[timeString release], timeString = nil;
[secondsString release], secondsString = nil;
[minutesString release], minutesString = nil;
[hoursString release], hoursString = nil;
NSString* totalDistanceString;
if(isCustomary) {
totalDistanceString = [[NSString alloc] initWithFormat:@"Total: %.2f mi", (float)distance * 0.000621371192f];
} else {
totalDistanceString = [[NSString alloc] initWithFormat:@"Total: %.2f km", (float)distance/1000.0f];
}
[customTopBar setTitle:totalDistanceString];
[totalDistanceString release];
}
NSDates और NSLogs के एक जोड़े के साथ मैं ने पाया है कि पूरे locationManager:didUpdateToLocation:fromLocation:
(न केवल लेबल को अपडेट करने में विधि) के निष्पादन कभी नहीं के बारे में अधिक से अधिक लेता है मेरे आईफोन 4 पर 8 एमएमएस; दूसरे शब्दों में, डेटा हैंडलिंग समस्या नहीं है।
हमें दिखाएं कि आपको स्थान डेटा कैसे प्राप्त हो रहा है। वह अंतराल सामान्य नहीं है। – sosborn
जोड़ा गया कोड। यदि आवश्यक हो तो मैं और अधिक पोस्ट कर सकता हूं। –
3-5 सेकंड एक असाधारण का थोड़ा सा हो सकता है; देर हो चुकी है और सीमा 3-5 बस किसी कारण से मेरे सिर में चली गई। कल मैं सटीक संख्या प्राप्त करने के लिए कुछ परीक्षण चलाऊंगा। –