Tag:ios encoding positioning parsing
locationtool.m//Handsome _ buy////Created by Beyond on 14-8-22.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "LocationTool.h" #import <CoreLocation/CoreLocation.h> #import "City.h" #import " MetaDataTool.h "@interface locationtool () <cllocationmanagerdelegate>{//Location manager, which is to locate the current user's latitude and longitude Cllocationman Ager *_mgr; Location decoding encoder Clgeocoder *_geo;} @end @implementation locationtoolsingleton_implementation (Locationtool)//tool class is initialized, create a location manager, Geo-Decode encoder, and set the proxy as the current tool class-( ID) init{if (self = [super init]) {//Location manager _mgr = [[Cllocationmanager alloc] init]; When it is positioned to achieve the latitude and longitude of the user, the agent _mgr.delegate = self is notified; Location Manager start Update [_mgr startupdatinglocation]; Clgeocoder can decode the city name _geo = [[[Clgeocoder Alloc] init] based on the longitude and latitude that the location manager has just identified; } return self;} #pragma mark-Location Manager proxy method, call--1------3-(void) Locationmanager: (Cllocationmanager *) Manager didupdatelocations: ( Nsarray *) locations{//1. Now that the user has been targetedBefore the latitude and longitude, then you can let the location manager stop positioning [_mgr stopupdatinglocation]; 2. Then, take out the first position, according to its latitude and longitude, through the Clgeocoder reverse resolution, to obtain the location of the city name, turn into a city object, with tools to save cllocation *loc = Locations[0]; 3.CLGeocoder reverse through latitude and longitude, get city name [_geo reversegeocodelocation:loc completionhandler: ^ (Nsarray *placemarks, Nserror *er ROR) {//Remove state from the dictionary----> xx clplacemark *place = placemarks[0]; NSString *cityname = place.addressdictionary[@ "state"]; Remove the last character "City", turn it into a city counterpart, save cityname with tools = [CityName substringtoindex:cityname.length-1]; From the tool's City dictionary, according to the city name, take out the corresponding city *city = [Metadatatool sharedmetadatatool].allcitiesdict[cityname]; Sets the current city object, which intercepts setter operations and notifies [metadatatool sharedmetadatatool].currentcity = cities; Positioning, and after parsing, use member variables to remember _locationcity = city; Assign a value to a member property for a GET request, providing latitude and longitude parameters with _locationcity.position = Loc.coordinate; }];}
Ios_21 Buy _ positioning and according to latitude and longitude, to parse out the city name