"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). Among them, Apple's own map in China uses 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 the 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 10M, this is very painful. At the same time because Apple is using the high-gold, will not be like Google Maps in the same domestic turtle access speed, do do some map-related things, very attractive.

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

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

Tips:

You need to cllocationmanager the location manager to manage the location. (Open and close, etc.)

When using the simulator, you need to set the latitude and longitude: debugging----------------" (Beijing: Latitude 39.9 ", longitude 116.) 3 ")

Locate the code for example:

#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/** * only to navigate to the user's location, it will be called (very high frequency of calls) * @param locations: Loaded Cllocation object */-(void) L Ocationmanager: (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 want to use location services only) [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 (with UI, be able to 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 detailed 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, define a pin, and so on, 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. It is necessary to introduce a bunch of frameworks, assuming that the simulator is replaced by the real machine, 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 Baidu site application key, and use the 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 the function, which can reduce the size of the SDK appropriately.

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

1, join? Baidu map view

In the delegate didfinishlaunching in the code, Baidu Hello World to the code is cut.

-(BOOL) Application: (UIApplication *) application didfinishlaunchingwithoptions: (Nsdictionary *) launchOptions {        Add to the Bmkmapmanager initialization and fill in the authorization key you requested    bmkmapmanager *mapmanager = [[Bmkmapmanager alloc]init];    Assuming that you want to focus on network and authorization validation 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;}

Viewcontroller is also very easy to use.

#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 use and the Apple Maps, 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


About the principle of positioning: http://www.2cto.com/kf/201404/289744.html


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


"IOS" Apple, Baidu map positioning 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.