Android 使用百度导航SDK 2,flutterui模板

根据用户的关键字,判断进行PoiNearbySearchOption还是PoiCitySearchOption

public void startSearchPlace(String where, LatLng centerLatLng,

boolean isNear) {

if (where != null && where.trim().length() > 0) {

if (-1 == NetworkUtil.getNetworkType(getApplicationContext())) {

NetworkUtil.noNetworkHint(getApplicationContext());

} else {

String textCity = etHistoryCity.getText().toString();

boolean isInputCity = textCity != null

&& textCity.trim().length() > 0;

if (isNear) {

// 周边搜索

Toast.makeText(

getApplicationContext(),

getResources().getString(R.string.poi_search_near)

  • where, Toast.LENGTH_SHORT).show();

PoiNearbySearchOption poiOption = new PoiNearbySearchOption();

poiOption.keyword(where);

poiOption.location(centerLatLng);

poiOption.radius(15 * 1000 * 1000); // 检索半径,单位:m

poiOption.sortType(PoiSortType.distance_from_near_to_far); // 按距离排序

// poiOption.sortType(PoiSortType.comprehensive); // 按综合排序

poiOption.pageNum(0); // 分页编号

poiOption.pageCapacity(10); // 设置每页容量,默认为每页10条

try {

mPoiSearch.searchNearby(poiOption);

} catch (Exception e) {

e.printStackTrace();

}

} else {

if (!isInputCity) {

// 周边搜索

Toast.makeText(

getApplicationContext(),

getResources().getString(

R.string.poi_search_near)

  • where, Toast.LENGTH_SHORT).show();

PoiNearbySearchOption poiOption = new PoiNearbySearchOption();

poiOption.keyword(where);

poiOption.location(centerLatLng);

poiOption.radius(15 * 1000 * 1000); // 检索半径,单位:m

poiOption

.sortType(PoiSortType.distance_from_near_to_far); // 按距离排序

// poiOption.sortType(PoiSortType.comprehensive); //

// 按综合排序

poiOption.pageNum(0); // 分页编号

poiOption.pageCapacity(10); // 设置每页容量,默认为每页10条

try {

mPoiSearch.searchNearby(poiOption);

} catch (Exception e) {

e.printStackTrace();

}

} else {

// 全国搜索

Toast.makeText(

getApplicationContext(),

getResources().getString(R.string.poi_in_city)

  • textCity

  • getResources().getString(

R.string.poi_search) + where,

Toast.LENGTH_SHORT).show();

PoiCitySearchOption poiOption = new PoiCitySearchOption();

poiOption.city(textCity);

poiOption.keyword(where);

poiOption.pageNum(0);

poiOption.pageCapacity(10);

mPoiSearch.searchInCity(poiOption);

}

// 存储搜索历

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

【docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

史到数据库,周边不需要

int existId = naviDb.getNaviIdByKey(where);

if (existId != -1) {

naviDb.deleteNaviHistoryById(existId);

}

NaviHistory naviHistory = new NaviHistory(where, textCity);

naviDb.addNaviHistory(naviHistory);

naviHistoryAdapter.notifyDataSetChanged();

}

}

}

}

坐标系转化:

/**

  • startLatitude,startLongitude为bd09ll

  • bdLocStartAfter.getLongitude()和bdLocStartAfter.getLatitude()即为转化过的坐标系

  • BDLocation.BDLOCATION_BD09LL_TO_GCJ02表示从bd09ll转成gcj02坐标系

*/

BDLocation bdLocStartBefore = new BDLocation();

bdLocStartBefore.setLatitude(startLatitude);

bdLocStartBefore.setLongitude(startLongitude);

BDLocation bdLocStartAfter = LocationClient.getBDLocationInCoorType(

bdLocStartBefore, BDLocation.BDLOCATION_BD09LL_TO_GCJ02);

周边和收藏

在导航的基础上,实现了周边搜索和收藏的功能:

这里写图片描述

这里写图片描述

实现方式:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值