OBJECTIVE-C Development--geo-coding and geo-coding of map positioning

Source: Internet
Author: User

We usually do map positioning, mainly by latitude and longitude to accurately locate a location.

But, we are human ah, we are not satellites AH.

The user on the map to find a place, we can not tell him, this place is longitude how many degrees, latitude how many degrees.

We're going to have to tell somebody a place name, right?

That's what we're talking about today in geocoding and geo-coding.

Geocoding: You say a place name, such as "West Lake", we give you to return its latitude and longitude, and then you find out the latitude and longitude to locate

Anti-geocoding: I'll tell you a latitude and longitude, and you return the place name by latitude. It's better to stick a pin on the map, and what's called a pin, we'll talk about it later.

First of all, my interface is this kind of paper, that is, two buttons, drag lines, generate two methods

The source code is as follows

//

Viewcontroller.m

demo3_ Anti-geo-coding

//

Created by Shiran on 16/3/23.

copyright©2016 year Shiran. All rights reserved.

//

#import "ViewController.h"

#import <CoreLocation/CoreLocation.h>

@interface viewcontroller ()

geo-coding

@property(nonatomic,strong)clgeocoder *geocoder;

@end

@implementation Viewcontroller

-(clgeocoder *) geocoder{

if (! _geocoder) {

_geocoder=[[clgeocoder alloc]init];

}

return _geocoder;

}

geo-coding

-(ibaction) Geocoder: (UIButton *) Sender {

nsstring *address=@ " West Lake ";

if (address. Length==0) {

return;

    }    

[self. Geocoder geocodeaddressstring: Address completionhandler: ^ (nsarray< Clplacemark *> * _nullable placemarks, nserror * _nullable error) {

if (error==nil) {

for (clplacemark *placemark in placemarks) {

NSLog(@ "%@", Placemark. Addressdictionary[@ "City"]);

NSLog(@ "%f,%f", Placemark. Location. Coordinate. Latitude, Placemark. Location. Coordinate. Longitude);

}

}

Else

{

NSLog(@ "%@", error);

}

}];

}

Anti-geo-coding

-(ibaction) Reversegeocoder: (UIButton *) Sender {

cllocation *loc = [[cllocation alloc]initwithlatitude: longitude: $];

[self. Geocoder reversegeocodelocation: Loc completionhandler: ^ (nsarray<Clplacemark *> * _nullable placemarks, nserror * _nullable error) { /c14>

if (error==nil) {

for (clplacemark *placemark in placemarks) {

NSLog(@ "%@,%@", Placemark. Addressdictionary[@ "City"],placemark. Name);

}

}

    }];  

}

-(void) viewdidload {

[Super viewdidload];

additional setup after loading the view, typically from a nib.

}

-(void) didreceivememorywarning {

[Super didreceivememorywarning];

//Dispose of any resources, can be recreated.

}

@end

Click the Geocoding button, the console output is as follows, because my simulator is in English, so the console printing is also in English, so foreign flavor ^_^

See, Nanchang latitude and longitude and latitude and longitude of Hangzhou have come out, it seems more than Hangzhou has a West lake, Nanchang also has West Lake Ah, long posture Bar ^_^

Click the Anti-geocoding button and the console output is as follows

Here, according to my latitude and longitude to return the address is Beijing Mentougou

OBJECTIVE-C Development--geo-coding and geo-coding of map positioning

Related Article

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.