Android Studio Baidu Map Development (8) Map tagged poi points and search POI point acquisition and utilization

Source: Internet
Author: User
Tags reverse geocoding lenovo

    • A brief description
    • Poi points marked in two maps
      • 1 interface
      • 2MapPoi class
      • 3 Getting POI
    • Three search keywords get poi point
      • Describe
      • 1combaidumapapisearchpoi
        • Interface Ongetpoisearchresultlistener
        • Poiresult class
        • Poiinfo class
        • Search POI
      • 2combaidumapapisearchsug
        • Interface
        • Suggestionresultseggestioninfo
        • Lenovo Search
    • Four search effects
      • 1 Lenovo Search Effect
      • 2 Direct Search Effect
      • 3 Select a Lenovo search result
    • Five summary

I. Brief description

Baidu Map poi points can be divided into two types: The map has been labeled points and search by keywords to get the poi point. For these two POI points, Baidu encapsulated into a different class and interface to achieve monitoring, the following simple to say a little.

two. Poi points are marked in the map

First encounter the first question on how to get the information of the marked point, in the Baidu map click on the marked point will have information, then on their own map how to generate click events?

(1) interface

Baidu provides a POI Click event Interface Baidumap.onmapclicklistener, which provides two methods, such as the following table.
(Test the function of Csdn's markdown editor to draw a table, not to center the title of the first line)

return type Method Description
Boolean Onmapclick (latlng point) Map Click event callback function
Boolean Onmappoiclick (Mappoi POI) In-map Poi Click event callback function
(2) Mappoi class
return type Method Description
Java.lang.String GetName () Get the name of the point of interest
Latlng GetPosition () Get the geographic coordinates of this point of interest
(3) Get POI

We just need to rewrite the Onmappoiclick ().
The code is as follows:

Baidumap.setonmapclicklistener (NewBaidumap.onmapclicklistener () {@Override             Public void Onmapclick(LATLNG latlng) {            }@Override             Public Boolean Onmappoiclick(Mappoi Mappoi) {String poiname = Mappoi.getname ();//poi Point NameLATLNG poiposition = Mappoi.getposition ();//poi Point coordinates                //The following is a casual application of their own                //Reverse geocoding based on POI Point coordinates                //reversesearch (poiposition);                 //Add layer display POI point                /*baidumap.clear ();                                     Baidumap.addoverlay (New Markeroptions (). Position (poiposition) Coordinate location. Icon (Bitmapdescriptorfactory.fromresource (r.drawabl                E.icon_marka). Title (Poiname)//title                ); Set the POI point to Map Center Baidumap.setmapstatus (MAPSTATUSUPDATEFACTORY.NEWLATLNG (poiposition)); * /                return true; }        });

Second, in order to get the other details of the POI point, because Mappoi does not have UID, I try to reverse geocode position, the result is still not satisfied, Baidu map directly click on the marked POI point, It is possible to get a lot of information about that point (visible in the third part of the Poiinfo), and for the moment there is no better way to solve it.

Three. Search keywords get poi point 1. Description

This function is the top of the Baidu Map home page, enter the place you want to go or food, shops and other nouns for poi search, but this part of the two query results:
(1) According to the keyword search directly to the relevant POI, the corresponding package for com.baidu.mapapi.search.poi;
(2) According to the keywords to get the POI, the corresponding package for COM.BAIDU.MAPAPI.SEARCH.SUG.
The so-called Lenovo search to get the poi, such as when we entered Shanghai, Baidu will be Lenovo search results prompted to you: Shanghai cuisine, SVW cars and so on, such as

2. Two poi are useful for different interfaces, callback functions, data types, such as the following table:

(1) Com.baidu.mapapi.search.poi interface: Ongetpoisearchresultlistener
type Method Description
void Ongetpoidetailresult (poidetailresult result) POI Detail Query Result callback
void Ongetpoiresult (poiresult result) Poi Query Result Callback

And then the main need to understand is

Poiresult class

Poiinfo class

Search POI
PrivateAutocompletetextview Keyworldsview;//Enter the Autocompletetextview of the search textPrivatePoisearch Mpoisearch;//poi Search ModuleMpoisearch = Poisearch.newinstance ();//InstantiationPoisearch.setongetpoisearchresultlistener ( This);//Monitor interface//*****//For example, add in the onclick event: Search, enter the callback function: Ongetpoiresult (poiresult result)Mpoisearch.searchincity ((NewPoicitysearchoption ())//. City (Currentloction.getcity ())//Locate cities for search City. Keyword (keyworldsview.gettext (). toString ())//Keywords. Pagenum (Loadindex));//page: The default starting from 0, paging is 10, so if the search results are greater than 10, to display the extra 10 of the part will need to loadindex= page number, or loadindex++ and so on to change Loadindex display the next page of data

Next is Ongetpoiresult (poiresult result)

  Public void Ongetpoiresult(Poiresult result) {if(Result = =NULL|| Result.error = = SearchResult.ERRORNO.RESULT_NOT_FOUND) {toast.maketext (Poisearchdemo. This,"Results not Found", Toast.length_long). Show ();return; }if(Result.error = = SearchResult.ERRORNO.NO_ERROR) {//Successfully searched for POI in incoming search city            //Some application of result            //are usually added to the map and then bound to some click events            //The official demo is handled as follows:Mbaidumap.clear (); Poioverlay overlay =NewMypoioverlay (MBAIDUMAP); Mbaidumap.setonmarkerclicklistener (overlay);//mypoioverlayextends Poioverlay; Poioverlay extends Overlaymanager            //Read the relationship between the three classes and instantly understand that we can also write overlay, rewrite some of the methods in the Overlaymanager can be            //For example, rewrite the Click event, this method is really good, for different types of layers may have different click events, Baidu map 3.4.0 after the support to set up a number of listening objects, but I have not completely mastered this method ...Overlay.setdata (result);//Layer DataOverlay.addtomap ();//Add to the map (all added are marker)Overlay.zoomtospan ();//guaranteed to show all marker            return; }if(Result.error = = SearchResult.ERRORNO.AMBIGUOUS_KEYWORD) {//When the input keyword is not found in the city, but when found in other cities, returns the list of cities that contain this keyword informationString Strinfo ="in"; for(Cityinfo cityInfo:result.getSuggestCityList ())                {Strinfo + = cityinfo.city; Strinfo + =","; } Strinfo + ="Find Results"; Toast.maketext (Poisearchdemo. This, Strinfo, Toast.length_long). Show (); }    }
(2) Com.baidu.mapapi.search.sug interface

The package is a void Ongetsuggestionresult (Suggestionresult result)

Suggestionresult.seggestioninfo

As you can see from the field descriptions, the results of the Lenovo search are the POI points that have been marked, with the UID

Lenovo Search
 @Override     Public void Ongetsuggestionresult(Suggestionresult Res) {if(res = =NULL|| Res.getallsuggestions () = =NULL) {return; } suggest =NewArraylist<string> ();//Get Lenovo Search results         for(Suggestionresult.suggestioninfo info:res.getAllSuggestions ()) {if(Info.key! =NULL) {Suggest.add (Info.key); }} Sugadapter =NewArrayadapter<string> (Poisearchdemo. ThisAndroid. R.layout.simple_dropdown_item_1line, suggest);//adapter, of course, can be processed with the Click event Plus itemKeyworldsview.setadapter (Sugadapter); Keyworldsview.setonitemclicklistener (NewAdapterview.onitemclicklistener () {@Override             Public void Onitemclick(adapterview<?> parent, view view,intPositionLongID) {Suggestionresult.suggestioninfo info = res.getallsuggestions (). get (position);//string uid = info.uid;Mpoisearch.searchpoidetail ((NewPoidetailsearchoption ())//Go to search for details of the POI->ongetpoidetailresult (poidetailresult result). Poiuid (Info.uid));        }        });    Sugadapter.notifydatasetchanged (); }
Four. Search results (1) Lenovo Search effect

(2) Direct Search effect

Search the results of the restaurant: in fact, it can also be personalized processing, such as locating near the search and so on

(3) Select a Lenovo search result

Selected in the display of a Lenovo search result:

Five. Summary

As mentioned earlier, Overlaymanager's rewrite, can let us to the layer to do some personalized processing is very easy, but the first time we did not find this, and there are some operations on the layer, so now want to re-composition layer related code really 1:30 will not finish.

Android Studio Baidu Map Development (8) Map tagged poi point and search POI Point acquisition and utilization

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.