मैं उद्देश्य-सी प्रोग्रामिंग के लिए नया हूं।आईओएस में CLGeoCoder का उपयोग करके ज़िप कोड/पोस्टल कोड का उपयोग करके अक्षांश देशांतर कैसे प्राप्त करें?
मैं ज़िप कोड/पोस्टल कोड द्वारा MapView में स्थान प्रदर्शित करना चाहता हूं। इसके लिए मुझे अक्षांश और देशांतर खोजना है।
मैंने पहले ही वेब-सेवा में ज़िप कोड को पास करके और सभी जानकारी के साथ प्रतिक्रिया प्राप्त करके कई समाधानों का उल्लेख किया था।
लेकिन मैं किसी भी वेब सेवा का उपयोग नहीं करना चाहता हूं। मैं इसे CLGeocoder
का उपयोग करके करना चाहता हूं, मैं अक्षांश देशांतर खोजने के लिए नीचे कोड का उपयोग कर रहा हूं।
-(IBAction)fetchCoordinates:(id)sender {
if (!self.geocoder) {
self.geocoder = [[CLGeocoder alloc] init];
}
NSString *address = [NSString stringWithFormat:@"%@ %@ %@", self.streetField.text, self.cityField.text, self.countryField.text];
[self.geocoder geocodeAddressString:address completionHandler:^(NSArray *placemarks, NSError *error) {
NSLog(@"mark :: %@", placemarks);
if ([placemarks count] > 0) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
self.coordinatesLabel.text = [NSString stringWithFormat:@"%f, %f", coordinate.latitude, coordinate.longitude];
if ([placemark.areasOfInterest count] > 0) {
self.nameLabel.text = [placemark.areasOfInterest objectAtIndex:0];
} else {
self.nameLabel.text = @"No Area of Interest Was Found";
}
}
}];
}
यह कोड काम कर रहा है अगर मैं शहर का नाम, देश का नाम या सड़क नाम पारित कर रहा हूं लेकिन ज़िप कोड को पार करते समय काम नहीं कर रहा हूं।
अग्रिम धन्यवाद।
मदद के लिए धन्यवाद ... लेकिन मैंने पहले ही यह किया है .... –
धन्यवाद निर्वापटेल। यह मेरे लिए काम करता है। –
मैंने इस कोड का जवाब [इस प्रश्न का उत्तर] (http://stackoverflow.com/a/33460514/981049) में किया है, और अक्षांश/देशांतर प्लेसमार्क शब्दकोश/ऑब्जेक्ट में वापस पाया जा सकता है। –