iOS development uses Clgeocoder to achieve latitude and longitude and address mutual search

Source: Internet
Author: User

  1. Add Corelocation.framework Frame

  2. Import #import <CoreLocation/CoreLocation.h>

  3. To query the latitude and longitude method by address:

  4.     CLGeocoder *geocoder = [[CLGeocoder alloc] init];     [geocoder geocodeaddressstring:@ "Xiangyang, Hubei"  completionhandler:^ (Nsarray* placemarks,  nserror* error) {        if  (!error)  {                          for  (Clplacemark* aplacemark in placemarks)              {                 nslog (@ "place--%@",  [aplacemark locality]);                 nslog (@ "Lat--%f--lon--%f", Aplacemark.location.coordinate.latitude,aplacemark.location.coordinate.longitude);             }        }         else{                         nslog (@ "error--%@", [error localizeddescription]);         }    }];

5.   Querying address by Latitude method:

 CLLocation * newLocation = [[CLLocation alloc]initWithLatitude:30.590865  Longitude:104.061792];        nslog (@ "-------based on latitude and longitude to reverse the location--%f--%f", Sendercoordinate.latitude,sendercoordinate.longitude);         clgeocoder *clgeocoder = [[clgeocoder alloc] init];    [ clgeocoder reversegeocodelocation:newlocation completionhandler: ^ (NSArray *placemarks, Nserror *error)  {                 nslog (@ "--array--%d---error--%@", (int) placemarks.count,error);                 if  (placemarks.count > 0)  {            clplacemark *placemark  = [placemarks objectatindex:0];            nsstring *city =  Placemark.administrativearea;            nslog (@ " Located at:%@ ", city);             nslog (@"%@ ", placemark.addressdictionary[@ "Name"]);        }     }];


iOS development uses Clgeocoder to achieve latitude and longitude and address mutual search

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.