"IOS" Apple, Baidu map positioning use and summary

Source: Internet
Author: User

More than 3 maps are used in iOS, Google Maps, Baidu maps, and Apple's own map (gold). One of the Apple's own maps used in China is the gold data. Apple abandoned its use of Google Maps after iOS 6 and switched to its own map. In the domestic use of more is Baidu, Apple brought a map (high), the following summary of these two.

First, the use of Apple Maps

Because Apple uses a gold map, plus some apple-made packages, it's easy to use. Do not need to introduce a third-party framework, compared to the use of Baidu Map SDK will make the source code and programs are much more than 10M, this is very painful. At the same time, because Apple is using the gold, will not like Google Maps in the domestic turtle-like access speed, do do some map-related things, very attractive.

The system is mainly used in two frames: Corelocation and Mapkit.

1, corelocation implementation positioning (This is no UI, just responsible for some data)

Tips:

Cllocationmanager Location Manager is required to manage targeting. (Open and close, etc.)

When using the simulator, you need to set the latitude and longitude: Debug--"Location--" custom location input latitude and longitude can be. (Beijing: Latitude 39.9 ", longitude 116.) 3 ")

Locate the code as follows:

#import <CoreLocation/CoreLocation.h> @interface Myviewcontroller () <cllocationmanagerdelegate>@ Property (Nonatomic, Strong) Cllocationmanager *locmgr; @end @implementation myviewcontroller-(Cllocationmanager *) locmgr{#warning location Service is not available if (![        Cllocationmanager locationservicesenabled]) return nil;        if (!_locmgr) {//create location Manager self.locmgr = [[Cllocationmanager alloc] init];    Set proxy self.locMgr.delegate = self; } return _locmgr;}        -(void) viewdidload{[Super Viewdidload];    Start locating the user's location [self.locmgr startupdatinglocation]; } #pragma mark-cllocationmanagerdelegate/** * As long as the location of the user, it will be called (very high frequency) * @param locations: Loaded with Cllocation object */-(void) Lo Cationmanager: (Cllocationmanager *) Manager didupdatelocations: (Nsarray *) locations{//cllocation storage is some latitude and longitude, speed and other information.    To get a location, you need to convert to geo-coding.        1. Remove Position object cllocation *loc = [locations Firstobject];        NSLog (@ "cllocation----%@", loc); 2. Remove the latitude and longitude cllocationcoordinate2d Coordinate = loc.coordinate;        3. Print latitude and longitude NSLog (@ "didupdatelocations------%f%f", Coordinate.latitude, Coordinate.longitude); Stop positioning (power-saving measures: Stop Location Services immediately if you do not want to use location services) [manager stopupdatinglocation];} @end

With Corelocation can also achieve: geographical information coding, anti-coding, latitude and longitude distance calculation.


2, Mapkit on the implementation of positioning (this is a UI, you can mark pins, display text, etc.)

Mapview is the map control that the Apple comes with, drag the control or the hand code to create the line.

#import <MapKit/MapKit.h> #import <CoreLocation/CoreLocation.h> @interface Myviewcontroller () < Mkmapviewdelegate> @property (Weak, nonatomic) Iboutlet Mkmapview *mapview; @end @implementation myviewcontroller-(        void) viewdidload{[Super Viewdidload];        1. Track user location (show user's specific location) Self.mapView.userTrackingMode = Mkusertrackingmodefollow;        2. Set the map type Self.mapView.mapType = Mkmaptypestandard; 3. Set proxy self.mapView.delegate = self;}  #pragma mark-mkmapviewdelegate/** * When the user's location is updated, it will be called * * @param userlocation represents the blue pin on the map data */-(void) Mapview: (Mkmapview    *) Mapview didupdateuserlocation: (mkuserlocation *) userlocation{Userlocation.title = @ "Cang teacher here"; Userlocation.subtitle = @ "Mr. Cang is here, you know?"        ";    Cllocationcoordinate2d Center = userLocation.location.coordinate;    NSLog (@ "%f%f", Center.latitude, Center.longitude); Sets the display range of the map to show it to the currently specified position mkcoordinatespan span = Mkcoordinatespanmake (0.021321, 0.019366);//This display size accuracy adjusts itself Mkcoordin Ateregion Region = Mkcoordinateregionmake (center, span); [Mapview setregion:region animated:yes];} @end

Mapview can also set a PIN, custom pin, etc., a lot of details of the function.


Second, the use of Baidu map

Baidu gave a hello world. Let's live and see. Just realized the display of a Baidu map view. Need to introduce a bunch of frameworks, if the simulator is a real machine swap, but also to switch the static library. (It is best to combine the debugging, and the library has more than 10M)

Http://developer.baidu.com/map/wiki/index.php?title=iossdk/guide/hellobaidumap

Tips:

Need to apply for key on Baidu website, and use simulator to locate, I test no response (with Baidu to the demo) ... We recommend using the real machine!

Baidu Maps uses objective-c++, which means there must be a. mm file.

Can be downloaded according to functionality, which reduces the size of the SDK appropriately.

Baidu gave the various functions of the sample code, watching or some of the eggs hurt, too many files. Http://developer.baidu.com/map/sdkiosdev-download.htm

1, add the view of Baidu map

In the delegate didfinishlaunching add this code on the line, Baidu Hello World to the code is cut.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {        Add the initialization for Bmkmapmanager and fill in the authorization key you requested    bmkmapmanager *mapmanager = [[Bmkmapmanager alloc]init];    If you want to focus on network and authorization authentication events, set generaldelegate parameter    BOOL ret = [Mapmanager start:@ "Your authorization key, change yourself to" generaldelegate:nil ";    if (!ret) {        NSLog (@ "Map Manager initialization failed!");    return YES;}

It's easy to use in Viewcontroller.

#import "BMKMapManager.h" #import "BMKMapView.h" @interface Xnviewcontroller () {    bmkmapview *_mapview;} @end @implementation xnviewcontroller-(void) viewdidload {    [super viewdidload];    _mapview = [[Bmkmapview alloc] Initwithframe:cgrectmake (N, A, ())];    [Self.view Addsubview:_mapview];}

2. Use Baidu Map to locate

Baidu's things or to see his own demo bar, Baidumap_iossdk_v2.3.0_sample project inside the Locationdemoviewcontroller class.

Tips:

used the Bmklocationservice.

There are many similarities between the usage and the Apple map, very easy.

It's not written here.



Baidu map can also be achieved: path planning, cloud retrieval, path planning, bus line query, etc., the function is quite rich.


Related information:

http://blog.csdn.net/totogo2010/article/details/7701026

Http://www.cnblogs.com/syxchina/archive/2012/10/14/2723522.html

Http://developer.baidu.com/map/sdk-ios.htm

Check out Apple's official documentation: Corelocation,mapview


Reprint Please specify source: http://blog.csdn.net/xn4545945


"IOS" Apple, Baidu map location use and summary

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.