0
我想從當前位置查找天氣。不提供郵政編碼查找天氣信息的地標
對於我所使用的代碼作爲
-(void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
[self.locationManager stopUpdatingLocation];
self.location = newLocation;
// NSLog(@"lat long = %f,%f",self.location.coordinate.latitude,self.location.coordinate.longitude);
// Geocode coordinate (normally we'd use location.coordinate here instead of coord).
// This will get us something we can query Google's Weather API with
if (boolCurrentlyWorking == NO) {
CLGeocoder* reverseGeocoder = [[CLGeocoder alloc] init];
if(reverseGeocoder)
{
[reverseGeocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark* placemark = [placemarks objectAtIndex:0];
if (placemark) {
//Using blocks, get zip code
NSString *zipCode = [placemark.addressDictionary objectForKey:(NSString*)kABPersonAddressZIPKey];
NSLog(@"placemark : %@ zipcode : %@",placemark.addressDictionary,zipCode);
}
}];
}else{
MKReverseGeocoder *geocoder = [[MKReverseGeocoder alloc] initWithCoordinate:self.location.coordinate];
geocoder.delegate = self;
[geocoder start];
}
}
boolCurrentlyWorking = YES;
}
我不及彼郵政編碼。
還發現didupdate位置的這種方法已被棄用,新的方法是
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
CLLocation *location = [locations lastObject];
CLLocation *newlocation = location;
NSLog(@"location : %@",location);
CLGeocoder* reverseGeocoder = [[CLGeocoder alloc] init];
if(reverseGeocoder)
{
[reverseGeocoder reverseGeocodeLocation:newlocation completionHandler:^(NSArray *placemarks, NSError *error) {
for(CLPlacemark *placemark in placemarks)
{
NSLog(@"plcaemark desc : %@",[placemark description]);
}
}];
}
}
但是,這也並不包含郵政編碼。
我得到這個描述
{
Country = India;
CountryCode = IN;
FormattedAddressLines = (
NH8C,
Gujarat,
India
);
Name = NH8C;
State = Gujarat;
Street = NH8C;
Thoroughfare = NH8C;
}
有沒有像它不提供郵政編碼信息,我們必須建立呢?如果是,那麼如何?
您是否嘗試過模擬其他位置以外的位置?我嘗試過自己,而且我沒有從地理編碼器接收印度許多地方的郵政編碼。 – Mark
是印度沒有郵政編碼或郵政編碼 – Heena