前提:集成高德地图
集成教程网上资源挺多,不再给出
检索功能:
逻辑代码:
public class RxvolleyActivity extends AppCompatActivity implements PoiSearch.OnPoiSearchListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_rxvolley); //天河为检索关键字 PoiSearch.Query query = new PoiSearch.Query("天河", "", ""); PoiSearch poiSearch = new PoiSearch(this, query); poiSearch.searchPOIAsyn(); poiSearch.setOnPoiSearchListener(this); } @Override public void onPoiSearched(PoiResult poiResult, int i) { ArrayList<PoiItem> list = poiResult.getPois(); for (int j = 0; j < list.size(); j++) { Log.i("++++", "地址:" + list.get(j).getTitle() + ",经纬度:" + list.get(j).getLatLonPoint().getLongitude()+ ":" + list.get(j).getLatLonPoint().getLatitude()); } } @Override public void onPoiItemSearched(PoiItem poiItem, int i) { } }
如果没有PoiSearch,添加下面依赖:
compile 'com.amap.api:search:latest.integration'
结果展示: