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.