[IOS] Apple, Baidu Map positioning use and summary, iosmap
IOS uses three more maps, google Maps, Baidu maps, and Apple's own maps (AMAP ). AMAP uses AMAP data in China. After iOS 6, Apple gave up using Google Maps and switched to its own map. Baidu and Apple's self-built map (AMAP) are mostly used in China. The two are summarized below.
I. Use of Apple Maps
Because Apple uses AMAP and some apple packages, it is also very convenient to use. There is no need to introduce a third-party framework. In comparison, using the Baidu map SDK will increase the source code and programs by more than 10 MB, which is a headache. At the same time, because Apple uses AMAP, it does not have the same access speed as Google Maps in domestic turtles. It is very attractive to do map-related things.
It mainly uses two frameworks of the system: CoreLocation and MapKit.
1. Implement CoreLocation positioning (this does not have a UI, but is responsible for some data)
Tips:
You need the CLLocationManager to manage the location. (Enable and end)
When using the simulator, you need to set the latitude and longitude: Debugging --> location --> Custom location and enter the latitude and longitude. (Beijing: north latitude 39.9 ", east longitude 116. 3 ")
The locating code is as follows:
# Import <CoreLocation/CoreLocation. h> @ interface MyViewController () <CLLocationManagerDelegate> @ property (nonatomic, strong) CLLocationManager * locMgr; @ end @ implementation MyViewController-(CLLocationManager *) locMgr {# warning locating service unavailable if (! [CLLocationManager locationServicesEnabled]) return nil; if (! _ LocMgr) {// create a positioning manager self. locMgr = [[CLLocationManager alloc] init]; // sets the proxy self. locMgr. delegate = self;} return _ locMgr;}-(void) viewDidLoad {[super viewDidLoad]; // start to locate the user's location [self. locMgr startUpdatingLocation];} # pragma mark-CLLocationManagerDelegate/*** is called as long as the user's location is located (the call frequency is particularly high) * @ param locations: hold the CLLocation object */-(void) locationManager :( CLLocationManager *) manager didUpdateLocations :( NSArray *) locations {// CLLocation stores information such as longitude and latitude, and speed. to obtain the geographic location, you need to convert it into a geographic location code. // 1. retrieve location object CLLocation * loc = [locations firstObject]; NSLog (@ "CLLocation ---- % @", loc); // 2. retrieve the longitude and latitude CLLocationCoordinate2D coordinate = loc. coordinate; // 3. print the longitude and latitude NSLog (@ "didUpdateLocations ------ % f", coordinate. latitude, coordinate. longpolling); // stop positioning (power-saving measure: if you do not want to use the locating service, stop locating the service immediately) [manager stopUpdatingLocation];} @ end
CoreLocation can also be used to encode geographical information, decomcode, and calculate the distance between longitude and latitude.
2. Implement positioning on MapKit (this has a UI that can mark pins and display text)
MapView is a map control that comes with apple. You can drag controls or create a mobile code.
# 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. tracking user location (Display User location) self. mapView. userTrackingMode = MKUserTrackingModeFollow; // 2. set map type self. mapView. mapType = MKMapTypeStandard; // 3. set proxy self. mapVi Ew. delegate = self;} # pragma mark-MKMapViewDelegate/*** when the user's location is updated, you will call ** @ param userLocation to indicate the data of the blue pin on the map */-(void) mapView :( MKMapView *) mapView didUpdateUserLocation :( MKUserLocation *) userLocation {userLocation. title = @ "instructor Cang here"; userLocation. subtitle = @ "instructor Cang is here. Do you know? "; CLLocationCoordinate2D center = userLocation. location. coordinate; NSLog (@ "% f", center. latitude, center. longpolling); // set the display range of the map to display it to the currently specified position MKCoordinateSpan span = MKCoordinateSpanMake (0.021321, 0.019366 ); // adjust the display size precision by yourself. MKCoordinateRegion region = MKCoordinateRegionMake (center, span); [mapView setRegion: region animated: YES];} @ end
MapView can also set pins, custom pins, and many other details.
Ii. Use of Baidu Map
A Hello World from Baidu. Let's take a look. Only a view of Baidu map is displayed. A bunch of frameworks need to be introduced. If the simulator is used for replacement, you have to switch the static library. (If debugging is performed, it is better to merge it and the database has more than 10 MB)
Http://developer.baidu.com/map/wiki/index.php? Title = iossdk/guide/hellobaidumap
Tips:
If you need to apply for a key on the Baidu website and use the simulator to locate the key, I will test it for no response (use the demo provided by Baidu )...... We recommend that you use a real machine!
Baidu map uses Objective-C ++, which means that there must be a. mm file.
You can download the SDK according to the function, which can reduce the SDK size.
Baidu provides sample code for various functions. It seems that there are still some egresses and there are too many files. Http://developer.baidu.com/map/sdkiosdev-download.htm
1. Add View of Baidu Map
Add this code to didFinishLaunching in delegate. The code given by Baidu Hello World is all cut.
-(BOOL) application :( UIApplication *) application didfinishlaunchingwitexceptions :( NSDictionary *) launchOptions {// Add initialization for BMKMapManager, enter the authorization Key BMKMapManager * mapManager = [[BMKMapManager alloc] init]. // if you want to pay attention to network and authorization verification events, set the generalDelegate parameter BOOL ret = [mapManager start: @ "your authorization key, change it to" generalDelegate: nil]; if (! Ret) {NSLog (@ "Map Manager initialization failed! ");} Return YES ;}
ViewController is 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(55, 100, 200, 200)]; [self.view addSubview:_mapView];}
2. Use Baidu map to locate
For Baidu's stuff, please refer to the demo provided by him. In the BaiduMap_IOSSDK_v2.3.0_Sample projectLocationDemoViewControllerClass.
Tips:
BMKLocationService
Its usage is similar to that of an Apple map, which is easy.
I will not write it here.
Baidu map can also implement path planning, cloud retrieval, path planning, bus line query, and other functions.
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
See apple's official documentation: CoreLocation, MapView
The principle of positioning: http://www.2cto.com/kf/201404/289744.html
Reprinted please indicate the source: http://blog.csdn.net/xn4545945
IOS Baidu map locating
You have met me many times. 1. The network of the mobile phone may be unstable. 2. The mobile phone memory is insufficient. 3. The software is updated. 4. The system is unstable. I used to solve these three problems in 1.3.4.
How does ios use Baidu map to implement peripheral search based on positioning?
Right-click any point on the map and a small form will pop up. Select "find near this point ......", The second dialog box appears. You can select pre-options such as bus stops, hotels, and hospitals, or enter what you want to find in the input box, a circle with a radius of 1 km appears, and all the specified search content is displayed in the circle.
The default radius of the circle is 1 km. You can expand the search radius by clicking the circle.