iOS Address encoding parsing

Source: Internet
Author: User

-(void) viewdidload

{

[Super Viewdidload];

Creating an Address resolver

Self.geocoder = [[Clgeocoder alloc] init];

}

-(Ibaction) encodetapped: (ID) sender

{

Gets the address string entered by the user

nsstring* addr = Self.addrField.text;

if (addr! = Nil && addr.length > 0)

{

[Self.geocoder geocodeaddressstring:addr

Completionhandler: ^ (Nsarray *placemarks, Nserror *error)

{

If the number of collection elements of the parsed result is greater than 1, the longitude and latitude information is obtained.

if (Placemarks.count > 0)

{

Only the first parse result is processed, and the list is used in the actual project to allow the user to select

clplacemark* placemark = placemarks[0];

cllocation* location = placemark.location;

Self.resultView.text = [NSString stringWithFormat:

@ "Longitude of%@:%g, Latitude:%g", addr,

Location.coordinate.longitude,

Location.coordinate.latitude];

}

Did not get the result of parsing.

Else

{

Use Uialertview to alert users

[[[Uialertview alloc] initwithtitle:@ "Reminder"

message:@ "The address you entered cannot be resolved" Delegate:nil

cancelbuttontitle:@ "OK" otherbuttontitles:nil]

Show];

}

}];

}

}

-(Ibaction) reversetapped: (ID) sender

{

nsstring* longitudestr = Self.longitudeField.text;

nsstring* latitudestr = Self.latitudeField.text;

if (longitudestr! = nil && longitudestr.length > 0

&& latitudestr! = Nil && latitudestr.length > 0)

{

Encapsulates the latitude and longitude entered by the user into a Cllocation object

cllocation* location = [[Cllocation alloc]

Initwithlatitude:[latitudestr Floatvalue]

Longitude:[longitudestr Floatvalue]];

[Self.geocoder reversegeocodelocation:location Completionhandler:

^ (Nsarray *placemarks, Nserror *error)

{

If the number of collection elements of the parsed result is greater than 1, the longitude and latitude information is obtained.

if (Placemarks.count > 0)

{

Only the first parse result is processed, and the actual project can use the list to let the user choose

clplacemark* placemark = placemarks[0];

Get Detailed address information

nsarray* Addrarray = [placemark.addressdictionary

objectforkey:@ "Formattedaddresslines"];

Stitching the detailed address into a string

nsmutablestring* addr = [[Nsmutablestring alloc] init];

for (int i = 0; i < addrarray.count; i + +)

{

[addr Appendstring:addrarray[i]];

}

Self.resultView.text = [NSString stringWithFormat:

@ "Longitude:%g, Latitude:%g's address is:%@",

Location.coordinate.longitude,

Location.coordinate.latitude, addr];

}

Did not get the result of parsing.

Else

{

Use Uialertview to alert users

[[[Uialertview alloc] initwithtitle:@ "Reminder"

message:@ "The address you entered cannot be resolved" Delegate:nil

cancelbuttontitle:@ "OK" otherbuttontitles:nil]

Show];

}

}];

}

}

iOS Address encoding parsing

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.