Ios_21 Buy _ positioning and according to latitude and longitude, to parse out the city name

Source: Internet
Author: User

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

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.