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) {
}
}
高德地图poi查询附近的建筑,poi文档很长,照着关键词来吧
最新推荐文章于 2024-09-17 17:55:49 发布