我正在通过天气应用程序教程。我在获取位置的反向地理编码时遇到问题。它不断收到标题中的错误。我明白它告诉我的只是卡在如何解决它。
下面是代码片段:
if (1)
{
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[locationManager startUpdatingLocation];
MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:locationManager];
geocoder.delegate = self;
[geocoder start];
}
else
{
[self performSelectorInBackground:@selector(showWeatherFor:) withObject:@"95014"];
}
就像我说的,我还在学习,所以解释一下你为什么做你所做的事情会很好。
您必须在CLLocation的委托方法中调用位置getter,您可以在其中获取GPS坐标。MKReverseGeocoder 的参数是 CLLocation 而不是 CLLocationManager
# pragma mark LocationGetter Delegate Methods
- (void)newPhysicalLocation:(CLLocation *)location {
//Geocoder is started only if a valid location is found.
self.reverseGeocoder = [[[MKReverseGeocoder alloc] initWithCoordinate:location] autorelease];
reverseGeocoder.delegate = self;
[reverseGeocoder start];
}