Dear user, note that Baidu map does not need to be tested online ..

Source: Internet
Author: User
Tags reverse geocoding

Dear user, note that Baidu map does not need to be tested online ..

Dear user, note that Baidu map does not need to be tested online...

Beautiful Life of the sun and fire god (http://blog.csdn.net/opengl_es)

This article follows the "signature-non-commercial use-consistency" creation public agreement

Reprinted please keep this sentence: Sun huoshen's beautiful life-this blog focuses on Agile development and mobile and IOT device research: iOS, Android, Html5, Arduino, pcDuino, otherwise, this blog post is rejected or reprinted. Thank you for your cooperation.


Recently, the Baidu map positioning function was used in iOS. Due to the unstable gateway of the company, it often caused LAN communication barriers. Therefore, a small Wi-Fi router was used to build a LAN environment, make sure that the development environment, mobile phones, and servers can work stably in a small environment. (My day, what is the situation ...)

In the positioning process, we can find that the frequently seen "network Success" and "Authorization success" are gone, and replaced by 2 and-300. (The log output area of XCode has output)

Later, I occasionally switched to the public network, checked the information, and forgot to switch back. I realized the root cause of the problem when I got back to work normally.

Specifically, we inserted the WAN port of small WIFI to the public transport switch, and then the test was OK. If we cut off the life-saving line, how can we test it, in addition, the two log output zones are replaced by numbers.

In addition, reverse geographic resolution requires a network connection, so that you can obtain the province, city, district (county) corresponding to the specified longitude and latitude from the Baidu server), street, no ......



Baidu map iOS SDK


Positioning features

For system reasons, iOS does not allow third-party positioning. Therefore, the positioning method in the map SDK is essentially a secondary encapsulation of native positioning. Through encapsulation, developers can use it more conveniently. In addition, the map SDK provides corresponding positioning layers (three-state positioning effects are supported) to help developers display the current location information.

Note: The system positioning function has been upgraded since iOS8. To achieve the latest adaptation, the SDK has also been modified since v2.5.0. before using the positioning function, developers can, in info. add in plist (either of the following, and both are added using NSLocationWhenInUseUsageDescription by default ):

NSLocationWhenInUseUsageDescription, which allows you to obtain the GPS description during foreground use.

NSLocationAlwaysUsageDescription, which allows permanent use of GPS description

Obtain Location Information

The positioning function can be used separately from the map function. The usage of the positioning function is as follows:

-(Void) viewDidLoad {// sets the positioning accuracy. Default Value: kCLLocationAccuracyBest [accuracy: accuracy]; // specifies the minimum distance Update (meter). Default Value: kCLDistanceFilterNone [accuracy: 100.f]; // initialize BMKLocationService _ locService = [[BMKLocationService alloc] init]; _ locService. delegate = self; // start LocationService [_ locService startUserLocationService];} // implement the related delegate processing Location Information Update // processing direction change information-(void) didUpdateUserHeading :( BMKUserLocation *) userLocation {// NSLog (@ "heading is % @", userLocation. heading);} // process Location Coordinate Update-(void) didUpdateBMKUserLocation :( BMKUserLocation *) userLocation {// NSLog (@ "didUpdateUserLocation lat % f, long % f", userLocation. location. coordinate. latitude, userLocation. location. coordinate. longpolling );}
Display positioning information

The function of displaying positioning information is located in the "map and cover" function module. Developers must select the function when using the function. The core code is as follows: (for complete information, see Demo)

// Normal state // The following _ mapView is the BMKMapView object _ mapView. showsUserLocation = YES; // display the positioning layer [_ mapView updateLocationData: userLocation];




Geocode

Geographic Encoding refers to the process of establishing a spatial coordinate relationship between address information. It can also be divided into forward and reverse map encoding.

Forward geocode refers to the process of converting address information into coordinate points.

The reverse geocoding service converts the address coordinate of the earth surface into a standard address. The reverse geographic code provides a coordinate positioning engine to help you reverse query the coordinates of a certain ground object to obtain the administrative division, street, and standard address information of the object. Through a wide range of data in the standard address library, users can create unlimited value in mobile query, business analysis, planning and analysis fields.

Examples of forward and reverse geocoding are as follows:

-(Void) viewDidLoad {// initialize the retrieval object _ searcher = [[BMKGeoCodeSearch alloc] init]; _ searcher. delegate = self; BMKGeoCodeSearchOption * geoCodeSearchOption = [[BMKGeoCodeSearchOption alloc] init]; geoCodeSearchOption. city = @ "Beijing"; geocodeSearchOption. address = @ "10 Shangdi 10 Street, Haidian District"; BOOL flag = [_ searcher geoCode: geoCodeSearchOption]; [geoCodeSearchOption release]; if (flag) {NSLog (@ "geo retrieval sent successfully");} else {NSLog (@ "geo retrieval failed ");} // initiate reverse geocode retrieval // CLLocationCoordinate2D pt = (bytes) {39.915, 116.404}; // BMKReverseGeoCodeOption * reverseGeoCodeSearchOption = [[// BMKReverseGeoCodeOption alloc] init]; // reverseGeoCodeSearchOption. reverseGeoPoint = pt; // BOOL flag = [_ searcher reverseGeoCode: reverseGeoCodeSearchOption]; // [reverseGeoCodeSearchOption release]; // if (flag) // {// NSLog (@ "anti-geo retrieval sent successfully"); //} // else // {// NSLog (@ "anti-geo retrieval failed "); // }}// implement Deleage processing callback results // receive forward encoding results-(void) onGetGeoCodeResult :( BMKGeoCodeSearch *) searcher result :( BMKGeoCodeResult *) result errorCode :( BMKSearchErrorCode) error {if (error = BMK_SEARCH_NO_ERROR) {// processing normal results here} else {NSLog (@ "sorry, no result found ");}} // receive the reverse geocode result //-(void) onGetReverseGeoCodeResult :( BMKGeoCodeSearch *) searcher result: // (BMKReverseGeoCodeResult *) result // errorCode :( BMKSearchErrorCode) error {// if (error = BMK_SEARCH_NO_ERROR) {// process the normal result here //} // else {// NSLog (@ "sorry, no result found "); ///} // set delegate to nil-(void) viewWillDisappear :( BOOL) animated {_ searcher when not in use. delegate = nil ;}

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.