Using the Baidu Map API in Android: query address information based on latitude and longitude

Source: Internet
Author: User
Tags class definition


Baidu Map Mobile version of the API contains not only the basic construction map interface, but also integrated a number of search services, including: Location search, peripheral search, range Search, public transport search, ride search, walking search, address information inquiries.



Baidu Map Mobile API provides the search service is mainly through the initialization of the Mksearch class, register the search results of the listening object Mksearchlistener to implement the asynchronous search service. First you need to customize a Mysearchlistener class that implements the Mksearchlistener interface and then obtains the corresponding search results by implementing different callback methods in the interface. The Mysearchlistener class is defined as follows:


/**
 * Implement MKSearchListener interface for implementing asynchronous search service and get search results
 *
 * @author liufeng
 */
Public class MySearchListener implements MKSearchListener {
/**
* Search for address information results based on latitude and longitude
* @param result search results
* @param iError error number (0 means correct return)
*/
@Override
Public void onGetAddrResult(MKAddrInfo result, int iError) {
}

/**
* Driving route search results
* @param result search results
* @param iError error number (0 means correct return)
*/
@Override
Public void onGetDrivingRouteResult(MKDrivingRouteResult result, int iError) {
}

/**
* POI search results (range search, city POI search, peripheral search)
* @param result search results
* @param type returns the result type (11,12,21:poi list 7: city list)
* @param iError error number (0 means correct return)
*/
@Override
Public void onGetPoiResult(MKPoiResult result, int type, int iError) {
}

/**
* Public exchange route search results
* @param result search results
* @param iError error number (0 means correct return)
*/
@Override
Public void onGetTransitRouteResult(MKTransitRouteResult result, int iError) {
}

/**
* Walking route search results
* @param result search results
* @param iError error number (0 means correct return)
*/
@Override
Public void onGetWalkingRouteResult(MKWalkingRouteResult result, int iError) {
}
}


Description: The above class definition only explains the function of the 5 methods of the Mksearchlistener class, all of which are NULL implementations and do not give a specific implementation. According to the content you want to retrieve, and then to implement the above corresponding method, you can get the search results. For example: 1 you want to search for address information through a geographical coordinate (latitude and longitude value), then only need to implement the above Ongetaddrresult () method to get the search results; 2 If you want to search the driving route information, The search results can be obtained only by implementing the Ongetdrivingrouteresult () method specifically.



Immediately thereafter, you need to initialize the Mksearch class:


Initialize Mksearch  
mmksearch = new Mksearch ();  
Mmksearch.init (Mapmanager, New Mysearchlistener ());


After two steps, you can search for the information you want by invoking some of the search methods provided by Mksearch.





Related Article

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.