IOS8 display of place names according to latitude and longitude

Source: Internet
Author: User

Most of the time when we do projects, we use the mobile phone to get the location, and then pass the data to the backstage, this is the iOS8 according to the latitude and longitude display place name of the demo

1. Import the framework

//

Nearbyviewcontroller.m

Neardemo

//

Created by Apple on 14/12/5.

Copyright (c) year Youdianshang. All rights reserved.

//

#import <CoreLocation/CoreLocation.h>

#import <MapKit/MapKit.h>

@interface nearbyviewcontroller () <Uitableviewdatasource,uitableviewdelegate, cllocationmanagerdelegate,datarequestmanagerdelegate>


{

nsuserdefaults *defaluts;

nsstring * JINGDUSTR;

nsstring *weidustr;

nsstring *locationaddress;

}

@property(nonatomic,retain)cllocationmanager *locationmanager;

@property(strong,nonatomic)UILabel *positionlabel;

/*

latitude and longitude related settings

*/


-(void) Getlocationall

{


self. Locationmanager = [[cllocationmanageralloc]init];

_locationmanager. Delegate = Self ;

_locationmanager. Desiredaccuracy =kcllocationaccuracybest;

_locationmanager. Distancefilter = Ten ;

[_locationmanagerrequestalwaysauthorization]; // Add this sentence

[_locationmanagerstartupdatinglocation];

}

/*

// get current location by latitude

-(void) change{

defaluts=[nsuserdefaultsstandarduserdefaults];


cllocationcoordinate2d coordinate;

Coordinate. latitude = [[nsstringstringwithformat:@ "%@",jingdustr] Floatvalue];

Coordinate. Longitude = [[nsstringstringwithformat:@ "%@",weidustr] Floatvalue];


cllocation *newlocation=[[cllocationalloc]initwithlatitude: Coordinate. LatitudeLongitude: coordinate. longitude];

clgeocoder *geocoder=[[clgeocoderalloc] init];

[Geocoder reversegeocodelocation: NewLocationcompletionhandler: ^ (nsarray* placemarks, nserror* error)

{

mkplacemark*placemark = [Placemarks objectatindex:0];

locationaddress = [nsstringstringwithformat:@ "%@%@%@%@", Placemark. Locality, Placemark. sublocality, Placemark. thoroughfare, Placemark. Subthoroughfare];

[defaluts setobject:locationaddress forkey:@ "Address"];

NSLog (@ " ultimate goal : 1:%@2:%@3:%@4:%@", Placemark. locality, Placemark. sublocality, Placemark. thoroughfare, Placemark. subthoroughfare);


}];


#pragma mark-- implement the Cllocationmanagerdelegate proxy method to obtain a geographic location (wrought)============================ ===============================================


//(1) Gets the location data, returns an array of cllocation , typically using one of the


-(void) Locationmanager: (cllocationmanager *) Manager didupdatelocations: (nsarray *) Locations

{

cllocation *currlocation = [Locations lastobject];

    nslog (@ " longitude =%f latitude =%f height =%f" , Currlocation. coordinate . latitude , Currlocation. coordinate . longitude , Currlocation. altitude );

jingdustr =[nsstringstringwithformat:@ "%f", currlocation. Coordinate. latitude];

weidustr =[nsstringstringwithformat:@ "%f", currlocation. Coordinate. longitude];

NSLog(@ "jijijijijij:%@",jingdustr);

[ Self change];


}

//(2) gets the callback method for the user's location data failure, which notifies the user

-(void) Locationmanager: (cllocationmanager *) Manager didfailwitherror: (nserror *) error

{

if ([Error code] = =kclerrordenied)

{

// access is denied

}

if ([Errorcode] = = Kclerrorlocationunknown) {

// cannot get location information

}

}




IOS8 display of place names according to latitude and longitude

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.