iOS device targeting

Source: Internet
Author: User

First, iOS talks about positioning

1, SignInSignOutViewController.h

@interface signinsignoutviewcontroller:uiviewcontroller<cllocationmanagerdelegate>{    CLLocationManager *_locationmanager;    Latitude    float _latitude;    Longitude    float _longitude;} @property (Nonatomic,retain) Cllocationmanager *locationmanager; @property (nonatomic) float latitude; @property ( nonatomic) float longitude; @end

2, SIGNINSIGNOUTVIEWCONTROLLER.M

#import "SignInSignOutViewController.h" @interface Signinsignoutviewcontroller () @end @implementation Signinsignoutviewcontroller@synthesize Locationmanager = _locationmanager; @synthesize latitude = _latitude;@    Synthesize longitude = _longitude;-(void) dealloc{Self.locationmanager = nil; [Super Dealloc];}    -(void) viewdidunload{[Super Viewdidunload]; Self.locationmanager = nil;}    -(void) viewdidload{[Super Viewdidload];    Instantiate a location manager cllocationmanager *cllocationmanager = [[Cllocationmanager alloc] init];    Self.locationmanager = Cllocationmanager;    [Cllocationmanager release];    Self.locationManager.delegate = self;    Self.locationManager.desiredAccuracy = Kcllocationaccuracybest;    [Self.locationmanager startupdatinglocation]; if (![     Cllocationmanager locationservicesenabled]) {[Globalapplication alert:@ ' prompt ': @ ' please turn on location: Settings > Privacy > Locations > Location Services];     }else{if ([Cllocationmanager authorizationstatus]! = kclauthorizationstatusauthorized) {       [Globalapplication alert:@ "prompt": @ "Location failed, please turn on location: Settings > Privacy > Location > Positioning service under XX application"]; }}} #pragma mark-cllocationmanagerdelegate#pragma mark-cllocationmanagerdelegate//triggered when the geographic location changes-(void) Locationmana GER: (Cllocationmanager *) Manager didupdatetolocation: (cllocation *) newlocation fromlocation: (cllocation *)    oldlocation{cllocationcoordinate2d CC,CC2;    Get latitude and longitude cc.longitude = newLocation.coordinate.longitude;    Cc.latitude = NewLocation.coordinate.latitude;    iOS coordinates (Google) converted to baidu coordinates CC2 = Bmkcoordictionarydecode (BMKBAIDUCOORFORWGS84 (cc));    Self.longitude = Cc2.longitude;    Self.latitude = Cc2.latitude; Stop location update [manager stopupdatinglocation];} Trigger when positioning error-(void) Locationmanager: (Cllocationmanager *) Manager didfailwitherror: (nserror *) error{NSString *    errorstring;    [Manager Stopupdatinglocation]; switch ([error code]) {Case kclerrordenied:errorstring = @ "Location failed, please turn on location: Settings > Privacy > Location > Positioning Services XX            Application "; Errorstring = @ "Access to location Services denied by user";        Break            Case kclerrorlocationunknown:errorstring = @ "Failed to locate, location data not available";        Break            default:errorstring = @ "Location failed, unknown error";    Break } [globalapplication alert:@ "positioning": errorstring];}

Second, Baidu map positioning (version number 2.1)

1,MainMenuViewController.h

@interface mainmenuviewcontroller:uiviewcontroller<bmkuserlocationdelegate> {    bmkuserlocation *_ MapLocation;    Latitude    float _latitude;    Longitude    float _longitude;} @property (nonatomic, retain) bmkuserlocation *maplocation; @property (nonatomic) float latitude; @property (nonatomic) float longitude; @end

2, MAINMENUVIEWCONTROLLER.M

#import "MainMenuViewController.h" @interface Mainmenuviewcontroller () @end @implementation Mainmenuviewcontroller@synthesize maplocation = _maplocation; @synthesize latitude = _latitude; @synthesize Longitude = _ longitude;    -(void) dealloc{self.maplocation = nil;    [Super Dealloc];    }-(void) viewdidunload{[Super Viewdidunload]; Self.maplocation = nil;}    -(void) viewdidload{[Super Viewdidload];    Bmkuserlocation *bmklocation = [[Bmkuserlocation alloc] init];    Bmklocation.delegate = self;    Self.maplocation = bmklocation;    [Bmklocation release]; [Self.maplocation Startuserlocationservice];} #pragma mark-baidu map/** * Call this function when the startuserlocationservice is positioned successfully * @param userloc my position coordinates */-(void)         Viewdidgetlocatinguser: (cllocationcoordinate2d) userloc{if (userloc.longitude! = 0 && Userloc.latitude! = 0) {        Self.longitude = Userloc.longitude;        Self.latitude = Userloc.latitude;    [Self.maplocation Stopuserlocationservice]; }}

iii. Results Method One:
ios:xxx.151604,xx.170156 (coordinates of the iOS collection)
baidu:xxx.162720,xx.174000 (Baidu conversion coordinates)
Method Two:
baidu:xxx.162716,xx.173980 (coordinates Baidu Collection)

iOS device targeting

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.