IOS geocoding/Anti-geocoding

Source: Internet
Author: User

I. Clgeocoder geocoding and geo-coding
  • 地理编码
    • Obtain specific location information (such as latitude and longitude, the full name of the address, etc.) based on the given place name
    // geo-coding methods  -(void) Geocodeaddressstring: (nsstring*) Addressstringcompletionhandler: (Clgeocodecompletionhandler) Completionhandler;

  • Anti-geocoding:
    • Obtain specific location information based on a given latitude and longitude
    Anti-geocoding Method-(void) Reversegeocodelocation: (cllocation*) Location Completionhandler: (Clgeocodecompletionhandler) Completionhandler;
    + Note:Clgeocodecompletionhandler-When geo-geocoding is complete, it ' calls Clgeocodecompletionhandler ' and can ' get to Clplacemark object ' "OBJC// This block pass 2 parameters //Error: When the coding error (such as coding not specific information) has the value //Placemarks: It contains a Clplacemark object typedef void (^clgeocodecompletionhandler) (nsarray*placemarks, nserror*error);
  • Clplacemark (locality: City name thoroughfare: Street Name: Full name cllocation *location)
Second, the application scenario
    • Used in conjunction with targeting to determine the specific address information for the current user
Third, examples
#import "ViewController.h"#import<CoreLocation/CoreLocation.h>@interfaceViewcontroller ()/** geo-coding*/@property (nonatomic, strong) Clgeocoder*GEOC, @property (weak, nonatomic) Iboutlet Uitextview*Addresstv, @property (weak, nonatomic) Iboutlet Uitextfield*LATITUDETF, @property (weak, nonatomic) Iboutlet Uitextfield*LONGITUDETF;@end@implementationViewcontroller#pragmaMark-Lazy Loading-(Clgeocoder *) geoc{if(!_GEOC) {_GEOC=[[Clgeocoder alloc] init]; }    return_GEOC;}-(void) Touchesbegan: (Nsset<uitouch *> *) touches withevent: (Uievent *)Event{    //[Self.view Endediting:yes];}/** geo-coding (address to Latitude)*/-(ibaction) geoCoder {nsstring*address =Self.addressTV.text; //Fault Tolerance    if([address length] = =0)        return; [SELF.GEOC geocodeaddressstring:address Completionhandler:^ (Nsarray<clplacemark *> * _nullable placemarks, Nserror *_nullable Error) {                //Clplacemark: Landmarks//Location: Position Object//addressdictionary: Address dictionary//Name: Address Details//locality: City                if(Error = =Nil) {Clplacemark*PL =[Placemarks Firstobject]; Self.addressTV.text=Pl.name; Self.latitudeTF.text=@ (pl.location.coordinate.latitude). StringValue; Self.longitudeTF.text=@ (pl.location.coordinate.longitude). StringValue; }Else{NSLog (@"Error"); }    }];}-(ibaction) Reversegeocoder {//get the latitude and longitude of user input    DoubleLatitude =[Self.latitudeTF.text Doublevalue]; DoubleLongitude =[Self.longitudeTF.text Doublevalue]; Cllocation*location =[[Cllocation alloc] Initwithlatitude:latitude longitude:longitude]; //anti-geocoding (latitude and longitude---address)[SELF.GEOC reversegeocodelocation:location completionhandler:^ (nsarray<clplacemark *> * _Nullable Placemarks, Nserror *_nullable Error) {        if(Error = =Nil) {Clplacemark*PL =[Placemarks Firstobject]; Self.addressTV.text=Pl.name; Self.latitudeTF.text=@ (pl.location.coordinate.latitude). StringValue; Self.longitudeTF.text=@ (pl.location.coordinate.longitude). StringValue; }Else{NSLog (@"Error"); }    }];}@end

IOS geocoding/Anti-geocoding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.