提交 23dcb8f7 authored 作者: 史晓晨's avatar 史晓晨

feat:调试逆地理编码;

上级 e58d685c
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.3-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
......@@ -4,10 +4,16 @@ import android.content.Context
import android.util.Log
import com.amap.api.services.core.LatLonPoint
import com.amap.api.services.core.PoiItem
import com.amap.api.services.geocoder.GeocodeResult
import com.amap.api.services.geocoder.GeocodeSearch
import com.amap.api.services.geocoder.RegeocodeQuery
import com.amap.api.services.geocoder.RegeocodeResult
import com.amap.api.services.poisearch.PoiResult
import com.amap.api.services.poisearch.PoiSearch
class ClxMapPoiSearchImpl : PoiSearch.OnPoiSearchListener, IPoiSearch {
class ClxMapPoiSearchImpl : PoiSearch.OnPoiSearchListener, IPoiSearch,
GeocodeSearch.OnGeocodeSearchListener {
/**
* 通过关键字搜索poi
......@@ -63,6 +69,22 @@ class ClxMapPoiSearchImpl : PoiSearch.OnPoiSearchListener, IPoiSearch {
poiSearch.searchPOIAsyn()
}
/**
* 逆地址编码
*/
override fun onGeocodeSearch(context: Context?, latitude: Double?, longitude: Double?) {
Log.d(Constants.TAG, "onGeocodeSearch: latitude = $latitude, longitude = $longitude")
val geocodeSearch = GeocodeSearch(context)
geocodeSearch.setOnGeocodeSearchListener(this)
// 第一个参数表示一个Latlng,第二参数表示范围多少米,第三个参数表示是火系坐标系还是GPS原生坐标系
val query = RegeocodeQuery(
LatLonPoint(latitude ?: 0.0, longitude ?: 0.0),
1000.0f,
GeocodeSearch.AMAP
)
geocodeSearch.getFromLocationAsyn(query);
}
/**===============================PoiSearch回调================================**/
......@@ -81,6 +103,24 @@ class ClxMapPoiSearchImpl : PoiSearch.OnPoiSearchListener, IPoiSearch {
Log.d(Constants.TAG, "onPoiItemSearched: poiItem = $poiItem")
}
/**
* 逆地址编码回调
*/
override fun onRegeocodeSearched(result: RegeocodeResult?, code: Int) {
// val arguments: MutableMap<String, Any> = HashMap(2)
Log.d(Constants.TAG, "onRegeocodeSearched: result: $result")
val map = Utils.buildSearchRegeocodeResultList(result, code)
Log.d(Constants.TAG, "onRegeocodeSearched: map: $map")
listener?.onPoiResult(map)
}
/**
* 地址编码回调
*/
override fun onGeocodeSearched(p0: GeocodeResult?, p1: Int) {
TODO("Not yet implemented")
}
/**===============================poi搜索结果listener================================**/
private var listener: OnPoiSearchedResult? = null
......@@ -92,4 +132,5 @@ class ClxMapPoiSearchImpl : PoiSearch.OnPoiSearchListener, IPoiSearch {
interface OnPoiSearchedResult {
fun onPoiResult(data: Map<String, Any>)
}
}
\ No newline at end of file
......@@ -43,23 +43,21 @@ class ClxMapPoiSearchPlugin : FlutterPlugin, MethodCallHandler,
"searchPOI#initPoiSearch" -> {
}
"searchPOI#keywords" -> mMapPoiSearchImpl?.onSearchKeywords(
mContext,
keywords
mContext, keywords
)
"searchPOI#around" -> mMapPoiSearchImpl?.onSearchAround(
mContext,
latitude,
longitude
mContext, latitude, longitude
)
"searchPOI#aroundAll" -> mMapPoiSearchImpl?.onSearchAroundAll(
mContext,
keywords,
latitude,
longitude,
city
mContext, keywords, latitude, longitude, city
)
"GeocodeSearch" -> mMapPoiSearchImpl?.onGeocodeSearch(mContext, latitude, longitude)
else -> result.notImplemented()
}
}
......
......@@ -10,4 +10,5 @@ interface IPoiSearch {
fun onSearchAroundAll(context: Context?, keywords: String?, latitude: Double?, longitude: Double?, city: String?)
fun onGeocodeSearch(context: Context?, latitude: Double?, longitude: Double?)
}
\ No newline at end of file
......@@ -26,6 +26,6 @@ subprojects {
project.evaluationDependsOn(':app')
}
task clean(type: Delete) {
tasks.register("clean", Delete) {
delete rootProject.buildDir
}
......@@ -29,11 +29,14 @@ class _MyAppState extends State<MyApp> {
// var result1 = await ClxMapPoiSearch.instance.aroundSearch(31.230378, 121.473658);
// print("------ result1: $result1");
var result2 = await ClxMapPoiSearch.instance.aroundSearchAll("停车场", city: "南京",);
print("------ result2: $result2");
}
void onSearch() async{
var result2 = await ClxMapPoiSearch.instance.aroundSearch(31.230378, 121.473658);
print("------ result2: $result2");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
......@@ -41,8 +44,11 @@ class _MyAppState extends State<MyApp> {
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: const Center(
child: Text('Running on:'),
body: InkWell(
onTap: onSearch,
child: const Center(
child: Text('Running on:'),
),
),
),
);
......
......@@ -37,4 +37,9 @@ class ClxMapPoiSearch {
return ClxMapPoiSearchPlatform.instance.getDistanceBetweenMapPoints(pointF, pointT);
}
/// 逆地址编码
Future<Map<String, dynamic>?> geocodeSearch(double latitude, double longitude) {
return ClxMapPoiSearchPlatform.instance.geocodeSearch(latitude, longitude);
}
}
......@@ -53,6 +53,16 @@ class MethodChannelClxMapPoiSearch extends ClxMapPoiSearchPlatform {
return PoiResult.toPoiResult(searchPOIResult["searchPOIResult"]);
}
/// 逆地址编码
@override
Future<Map<String, dynamic>?> geocodeSearch(double? latitude, double? longitude) async {
var result = await methodChannel.invokeMethod<dynamic>('GeocodeSearch', <String, dynamic>{
'latitude': latitude,
'longitude': longitude,
});
return result;
}
/// 两点间的直线距离计算
@override
Future<double?> getDistanceBetweenMapPoints(List<double?> pointF, List<double?> pointT,) async {
......
......@@ -53,6 +53,11 @@ abstract class ClxMapPoiSearchPlatform extends PlatformInterface {
throw UnimplementedError('aroundSearchAll() has not been implemented.');
}
/// 逆地址编码
Future<Map<String, dynamic>?> geocodeSearch(double? latitude, double? longitude) async {
throw UnimplementedError('geocodeSearch() has not been implemented.');
}
/// 两点间的直线距离计算
Future<double?> getDistanceBetweenMapPoints(
List<double?> pointF,
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论