現在地から天気を知りたい。
そのために私はコードを次のように使用しました
-(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 locationのこのメソッドは非推奨になり、新しいメソッドは
-(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;
}
郵便番号情報を提供しておらず、作成する必要があるようなものはありますか?はいの場合、どのように?