高德地图poi查询附近的建筑,poi文档很长,照着关键词来吧

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;

import com.amap.api.services.core.LatLonPoint;
import com.amap.api.services.core.PoiItem;
import com.amap.api.services.core.SuggestionCity;
import com.amap.api.services.poisearch.PoiResult;
import com.amap.api.services.poisearch.PoiSearch;
import com.flawdemo.util.ToastUtil;

import java.util.List;

public class MainActivity extends AppCompatActivity implements PoiSearch.OnPoiSearchListener {

    private int currentPage;
    private LatLonPoint lp = new LatLonPoint(40.045464, 136.30345);
    private PoiSearch.Query query;
    private PoiSearch poiSearch;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        String keyWord = "楼";
        currentPage = 0;
        // 第一个参数表示搜索字符串,第二个参数表示poi搜索类型,第三个参数表示poi搜索区域(空字符串代

表全国)
        query = new PoiSearch.Query(keyWord, "", "北京");

        query.setPageSize(20);//setting how mang itmes to return;
        query.setPageNum(currentPage);//setup query the first page;

        if (lp != null) {
            poiSearch = new PoiSearch(this, query);
            poiSearch.setOnPoiSearchListener(this);
            // 设置搜索区域为以lp点为圆心,其周围15000米范围
            poiSearch.setBound(new PoiSearch.SearchBound(lp, 5000 * 3, true));
            poiSearch.searchPOIAsyn();//asyn search
        }
    }

    private PoiResult poiResult;//the result of the poi
    private List<PoiItem> poiItems;//poi数据

    @Override
    public void onPoiSearched(PoiResult result, int rcode) {
        Log.i("tags", "poiItems页数:" + result.getPageCount());//这个page不准,说是30页,但是我查询能到43页左右
        if (rcode == 1000) {
//            检测搜索结果
            if (result != null && result.getQuery() != null) {
//                是否是同一条,避免多次多点查询的时候混乱
                if (result.getQuery().equals(query)) {
                    poiResult = result;
                    poiItems = poiResult.getPois();
//                   获取poitem数据
                    List<SuggestionCity> suggestionCities = poiResult.getSearchSuggestionCitys();
                    if (poiItems != null && poiItems.size() > 0) {
                        for (int i = 0; i < poiItems.size(); ++i) {//这里是查出的全部信息,这里是你想要的
                            PoiItem poiItem = poiItems.get(i);
                            Log.i("tags", "poiItems内容:" + poiItem.getTitle()
                                    + "," + poiItem.getAdName() + "," + poiItem.getBusinessArea()
                                    + "," + poiItem.getCityName() + "," + poiItem.getDirection() +

","
                                    + poiItem.getEmail() + "," + poiItem.getProvinceName() + "," +

poiItem.getTel() +
                                    "," + poiItem.getLatLonPoint().getLatitude()
                                    + "," + poiItem.getLatLonPoint().getLongitude());
                        }
  //                      for (int i = 0; i < suggestionCities.size(); i++) {//这个是空的
        //                    SuggestionCity suggestionCity = suggestionCities.get(i);
     //                       Log.i("tags", "suggestionCites:" + suggestionCity.getCityName()
       //                             + "," + suggestionCity.getAdCode());
        //                }
                    } else if (suggestionCities != null && suggestionCities.size() > 0) {
//                        showSuggestCity(suggestionCities);
                    } else {
                        ToastUtil.show(MainActivity.this, R.string.no_result);
                    }
                }
            } else {
                ToastUtil.show(MainActivity.this, R.string.no_result);
            }
        }
    }

    @Override
    public void onPoiItemSearched(PoiItem poiItem, int i) {

    }
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值