AMAP tutorial _ poi search and display, AMAP tutorial _ poi

Source: Internet
Author: User

AMAP tutorial _ poi search and display, AMAP tutorial _ poi

Recently, I plan to use the APP similar to Shenzhen Tong. The UI is ready. I have read the APP query interface and can query it if the network is disconnected. This indicates that the data is stored in the database or is connected to the Internet for the first time, just put all the data on the website. I just want to use the query provided by the map.

I used to contact Baidu maps, but Baidu maps were not very useful. I also used AMAP to view official documents on project establishment,

Autonavi configuration project


It is not very clear about the subsequent projects. It depends on the official demo. I just want to write one by myself. Check the UI. I will paste the UI code again.


Edittext input information button submits data for query listview display query callback data

<? Xml version = "1.0" encoding = "UTF-8"?> <LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android" xmlns: tools = "http://schemas.android.com/tools" android: layout_width = "match_parent" android: layout_height = "match_parent" android: orientation = "vertical"> <LinearLayout android: layout_width = "match_parent" android: layout_height = "wrap_content" android: orientation = "horizontal" tools: ignore = "UselessLeaf, uselessParent "> <EditText android: id =" @ + id/et_keyword "android: layout_width =" 0dp "android: layout_height =" wrap_content "android: layout_weight =" 2 "android: hint = "Enter the keyword"/> <Button android: id = "@ + id/btn_search" android: layout_width = "0dp" android: layout_height = "wrap_content" android: layout_weight = "1" android: text = "Search"/> </LinearLayout> <ListView android: id = "@ + id/lv_result" android: layout_width = "match_parent" android: layout_height = "match_parent"/> </LinearLayout>


Step 1: Initialize the control

// Control-related private EditText mEtKeyword; private Button mBtnSearch; private ListView mLvResult;

private void initView() {mEtKeyword = (EditText) findViewById(R.id.et_keyword);mBtnSearch = (Button) findViewById(R.id.btn_search);mLvResult = (ListView) findViewById(R.id.lv_result);mBtnSearch.setOnClickListener(this);mLvResult.setOnItemClickListener(this);}

The second part is button click event processing.

@ Overridepublic void onClick (View v) {switch (v. getId () {case R. id. btn_search: // 1. obtain user input data String keyword = mEtKeyword. getText (). toString (); // 2. determines whether the user input is null if (keyword. trim (). length () = 0) {Toast. makeText (this, "Enter the query condition", Toast. LENGTH_LONG ). show ();} else {// 3. search (keyword);} break; default: break ;}}

Step 3: View search data and return data

Now let's take a look at what the official documentation says.

Keyword Search

1. Search Condition settings

You need to set the search condition through descriearch. Query (String query, String ctgr, String city. The "query" parameter is the search keyword, "ctgr" is the search type (type reference table obtained from the relevant download), and "city" is the search city. Enter at least one keyword and type. You must enter a search city.

You can use Query. setPageSize (int) to set the number of results on each page;

Query the page number through Query. setPageNum (int.

2. Send requests and receive data.

Use descriearch. searchPOIAsyn () to search for POI. Use the deleearch. setonreceivearchlistener () method to set the listener and process the returned results in the onreceivearchched (PoiResult poiResult, int rCode) method of the receivearch. onreceivearchlistener interface callback method. If no POI result is returned when you specify a search city, the recommended city name containing the keyword is returned. If no search result is displayed for a keyword, the recommended search keyword is returned.

SO we first define

// Point of interest first
Private elastic earch search;
// The query data class is returned.
Private PoiSearch. Query query;

Because I am in Shenzhen, I will search for things in Shenzhen.

Private void search (String keyword) {// initialize the query condition Query = new query (keyword, null, "Shenzhen"); query. setPageSize (10); query. setPageNum (1); // search point of interest search = new PoiSearch (this, query); // asynchronous search. searchPOIAsyn (); search. setondomainearchlistener (this );}

Step 4: Check the callback data. Because we have set up to return 10 pieces of data, use listview to display the data.

/* Callback point of interest query callback ------------------ */@ Overridepublic void onPoiItemDetailSearched (PoiItemDetail arg0, int arg1) {}@ Overridepublic void onincluearched (PoiResult poiResult, int rCode) {List <String> strs = new ArrayList <String> (); items = poiResult. getPois (); if (items! = Null & items. size ()> 0) {PoiItem item = null; for (int I = 0, count = items. size (); I <count; I ++) {item = items. get (I); strs. add (item. getTitle ();} // assign a value to the ListView. The ArrayAdapter <String> array = new ArrayAdapter <String> (this, android. r. layout. simple_list_item_1, strs); mLvResult. setAdapter (array) ;}}/* -------------------- point of interest query callback --------------------*/




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.