IOS native Map geocoding and anti-geocoding

Source: Internet
Author: User

When we want to implement the function in the app: Enter place name, code for latitude and longitude, realize navigation function. So, I need to use the Geocoding feature in the native map, and in the core location, it includes the positioning, geocoding (including the anti-coding) feature.

Import in File

#import <CoreLocation/CoreLocation.h>

Geocoding:

/** geocoding */-(void) Geocoder {        clgeocoder *geocoder=[[clgeocoder alloc]init];        NSString *addressstr = @ "Guangdong province Shenzhen Bao ' an district";//location information        [Geocoder geocodeaddressstring:addressstr completionhandler:^ ( Nsarray<clplacemark *> * _nullable placemarks, Nserror * _nullable error) {        if (Error!=nil | | placemarks.count== 0) {            return;        }        Create Placemark object        clplacemark *placemark=[placemarks firstobject];        Longitude        nsstring *longitude =[nsstring stringwithformat:@ "%f", placemark.location.coordinate.longitude];        Latitude        nsstring *latitude =[nsstring stringwithformat:@ "%f", placemark.location.coordinate.latitude];                NSLog (@ "Longitude:%@, Latitude:%@", longitude,latitude);            }];    }

Geo-coding:

/** geo-*/-(void) reversegeocoder{    //Create GeoCode Objects    Clgeocoder *geocoder=[[clgeocoder alloc]init];        Longitude    NSString *longitude = @ "113.23";    Latitude    nsstring *latitude = @ "23.16";            Create location    cllocation *location=[[cllocation alloc]initwithlatitude:[latitude Floatvalue] Longitude:[longitude Floatvalue]];            Anti-geocoding    [Geocoder reversegeocodelocation:location completionhandler:^ (nsarray<clplacemark *> * _Nullable Placemarks, Nserror * _nullable error) {        //To determine if there is an error or if Placemarks is empty if        (Error!=nil | | placemarks.count==0) { C12/>nslog (@ "%@", error);            return;        }        For (Clplacemark *placemark in placemarks) {            //detail address            nsstring *addressstr = placemark.name;            NSLog (@ "Detailed address 1:%@", addressstr);            NSLog (@ "Detailed address 2:%@", placemark.addressdictionary);            NSLog (@ "Detailed address 3:%@", placemark.locality);        }            ];}


Demo:https://github.com/jnkindle/geocoderandreversereocoder

/**

* AUTHOR:JN

* Github:https://github.com/jnkindle

* Cnblogs:http://www.cnblogs.com/jnkindle

* qq:1294405741

*/

IOS native Map geocoding and 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.