提交 403fe0bf authored 作者: shixiaochen's avatar shixiaochen

1、增加distance

上级 011c4629
package com.clx.clx_map_poi_search; package com.clx.clx_map_poi_search
import android.util.Log; import android.util.Log
import com.amap.api.services.poisearch.PoiResult
import com.amap.api.services.core.AMapException; import com.amap.api.services.core.AMapException
import com.amap.api.services.core.PoiItem; import com.amap.api.services.core.PoiItem
import com.amap.api.services.geocoder.RegeocodeAddress; import com.amap.api.services.help.Tip
import com.amap.api.services.geocoder.RegeocodeResult; import com.amap.api.services.geocoder.RegeocodeResult
import com.amap.api.services.help.Tip; import com.amap.api.services.geocoder.RegeocodeAddress
import com.amap.api.services.poisearch.PoiResult; import java.util.ArrayList
import java.util.HashMap
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** /**
* @Author : shixiaochen * @Author : shixiaochen
* @Time : 2022/4/15 * @Time : 2022/4/15
* @Description : * @Description :
*/ */
public class Utils { object Utils {
/** /**
* poi搜索 数据 * poi搜索 数据
* *
...@@ -28,29 +23,30 @@ public class Utils { ...@@ -28,29 +23,30 @@ public class Utils {
* @param code 响应码 * @param code 响应码
* @return 返回数据 * @return 返回数据
*/ */
public static List<Map<String, Object>> buildSearchResultList(PoiResult poiResult, int code) { fun buildSearchResultList(poiResult: PoiResult, code: Int): List<Map<String, Any>> {
List<Map<String, Object>> result = new ArrayList<>(); val result: MutableList<Map<String, Any>> = ArrayList()
if (code == AMapException.CODE_AMAP_SUCCESS) { if (code == AMapException.CODE_AMAP_SUCCESS) {
ArrayList<PoiItem> list = poiResult.getPois(); val list = poiResult.pois
Log.d(Constants.TAG, "buildSearchResultList: list = " + list); Log.d(Constants.TAG, "buildSearchResultList: list = $list")
if (list != null) { if (list != null) {
for (PoiItem poiItem : list) { for (poiItem in list) {
HashMap<String, Object> map = new HashMap<>(); val map = HashMap<String, Any>()
map.put("latitude", poiItem.getLatLonPoint().getLatitude()); map["latitude"] = poiItem.latLonPoint.latitude
map.put("longitude", poiItem.getLatLonPoint().getLongitude()); map["longitude"] = poiItem.latLonPoint.longitude
map.put("provinceName", poiItem.getProvinceName()); map["provinceName"] = poiItem.provinceName
map.put("provinceCode", poiItem.getProvinceCode()); map["provinceCode"] = poiItem.provinceCode
map.put("cityName", poiItem.getCityName()); map["cityName"] = poiItem.cityName
map.put("cityCode", poiItem.getCityCode()); map["cityCode"] = poiItem.cityCode
map.put("adName", poiItem.getAdName()); map["adName"] = poiItem.adName
map.put("businessArea", poiItem.getBusinessArea()); map["businessArea"] = poiItem.businessArea
map.put("snippet", poiItem.getSnippet()); map["snippet"] = poiItem.snippet
map.put("title", poiItem.getTitle()); map["title"] = poiItem.title
result.add(map); map["distance"] = poiItem.distance
result.add(map)
} }
} }
} }
return result; return result
} }
/** /**
...@@ -60,31 +56,31 @@ public class Utils { ...@@ -60,31 +56,31 @@ public class Utils {
* @param code 响应码 * @param code 响应码
* @return 返回数据 * @return 返回数据
*/ */
public static List<Map<String, Object>> buildSearchInputResultList(List<Tip> list, int code) { fun buildSearchInputResultList(list: List<Tip>?, code: Int): List<Map<String, Any?>> {
List<Map<String, Object>> result = new ArrayList<>(); val result: MutableList<Map<String, Any?>> = ArrayList()
if (code == AMapException.CODE_AMAP_SUCCESS) { if (code == AMapException.CODE_AMAP_SUCCESS) {
Log.d("TAG", "buildSearchResultList: list = " + list); Log.d("TAG", "buildSearchResultList: list = $list")
if (list != null) { if (list != null) {
for (Tip tip : list) { for (tip in list) {
HashMap<String, Object> map = new HashMap<>(); val map = HashMap<String, Any?>()
map.put("name", tip.getName()); map["name"] = tip.name
map.put("address", tip.getAddress()); map["address"] = tip.address
map.put("adCode", tip.getAdcode()); map["adCode"] = tip.adcode
map.put("district", tip.getDistrict()); map["district"] = tip.district
map.put("poiID", tip.getPoiID()); map["poiID"] = tip.poiID
map.put("typeCode", tip.getTypeCode()); map["typeCode"] = tip.typeCode
if (tip.getPoint() != null) { if (tip.point != null) {
map.put("latitude", tip.getPoint().getLatitude()); map["latitude"] = tip.point.latitude
map.put("longitude", tip.getPoint().getLongitude()); map["longitude"] = tip.point.longitude
} else { } else {
map.put("latitude", null); map["latitude"] = null
map.put("longitude", null); map["longitude"] = null
} }
result.add(map); result.add(map)
} }
} }
} }
return result; return result
} }
/** /**
...@@ -94,25 +90,24 @@ public class Utils { ...@@ -94,25 +90,24 @@ public class Utils {
* @param code 响应码 * @param code 响应码
* @return 返回数据 * @return 返回数据
*/ */
public static Map<String, Object> buildSearchRegeocodeResultList(RegeocodeResult regeocode, int code) { fun buildSearchRegeocodeResultList(regeocode: RegeocodeResult?, code: Int): Map<String, Any> {
Map<String, Object> result = new HashMap<>(); val result: MutableMap<String, Any> = HashMap()
if (code == AMapException.CODE_AMAP_SUCCESS) { if (code == AMapException.CODE_AMAP_SUCCESS) {
if (regeocode != null && regeocode.getRegeocodeAddress() != null) { if (regeocode != null && regeocode.regeocodeAddress != null) {
RegeocodeAddress address = regeocode.getRegeocodeAddress(); val address = regeocode.regeocodeAddress
result.put("province", address.getProvince()); result["province"] = address.province
result.put("city", address.getCity()); result["city"] = address.city
result.put("town", address.getTownship()); result["town"] = address.township
result.put("street", address.getBuilding()); result["street"] = address.building
result.put("district", address.getDistrict()); result["district"] = address.district
result.put("address", address.getFormatAddress()); result["address"] = address.formatAddress
result.put("adCode", address.getAdCode()); result["adCode"] = address.adCode
result.put("cityCode", address.getCityCode()); result["cityCode"] = address.cityCode
result.put("country", address.getCountry()); result["country"] = address.country
result.put("neighborhood", address.getNeighborhood()); result["neighborhood"] = address.neighborhood
result.put("townCode", address.getTowncode()); result["townCode"] = address.towncode
} }
} }
return result; return result
} }
}
} \ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论