Toggle navigation
Toggle navigation
This project
Loading...
Sign in
OnePoem
/
OnePoem-App
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
reason
2022-08-12 11:22:51 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
6d146bbc1b02cb7004881bd42dc0ba71b15ded1e
6d146bbc
1 parent
27d5180a
百度定位逻辑
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
99 additions
and
43 deletions
lib/generated/json/collect_entity.g.dart
lib/poem/page/poem_publish.dart
lib/poem/page/select_address_page.dart
pubspec.yaml
lib/generated/json/collect_entity.g.dart
View file @
6d146bb
...
...
@@ -95,4 +95,4 @@ CollectError $CollectErrorFromJson(Map<String, dynamic> json) {
Map
<
String
,
dynamic
>
$CollectErrorToJson
(
CollectError
entity
)
{
final
Map
<
String
,
dynamic
>
data
=
<
String
,
dynamic
>{};
return
data
;
}
}
\ No newline at end of file
...
...
lib/poem/page/poem_publish.dart
View file @
6d146bb
...
...
@@ -13,10 +13,10 @@ import 'package:Parlando/routers/routers.dart';
import
'package:Parlando/widgets/my_app_bar.dart'
;
import
'package:Parlando/extension/int_extension.dart'
;
import
'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'
;
import
'package:getwidget/getwidget.dart'
;
import
'package:path_provider/path_provider.dart'
;
import
'../../map/poi_search_model.dart'
;
import
'../poem_router.dart'
;
class
PoemPublish
extends
StatefulWidget
{
...
...
@@ -110,11 +110,11 @@ class PoemPublishState extends State<PoemPublish> {
NavigatorUtils
.
pushResult
(
context
,
PoemRouter
.
addressSelectPage
,
(
result
)
{
setState
(()
{
final
PoiSearch
model
=
result
as
PoiSearch
;
_longitude
=
model
.
longitude
!
;
_latitude
=
model
.
latitude
!
;
final
BMFPoiInfo
model
=
result
as
BMFPoiInfo
;
_longitude
=
model
.
pt
!.
longitude
.
toString
()
;
_latitude
=
model
.
pt
!.
latitude
.
toString
()
;
_address
=
'
${model.province
Name!}
${model.cityName!}
${model.adName!}
${model.titl
e!}
'
;
'
${model.province
!}
${model.city!}
${model.area!}
${model.nam
e!}
'
;
});
});
},
...
...
lib/poem/page/select_address_page.dart
View file @
6d146bb
import
'dart:io'
;
import
'package:flutter/material.dart'
;
import
'package:Parlando/routers/fluro_navigator.dart'
;
import
'package:Parlando/util/toast_utils.dart'
;
import
'package:Parlando/widgets/my_button.dart'
;
import
'package:Parlando/widgets/search_bar.dart'
;
import
'package:flutter_baidu_mapapi_base/flutter_baidu_mapapi_base.dart'
;
import
'package:flutter_baidu_mapapi_map/flutter_baidu_mapapi_map.dart'
;
import
'package:flutter_baidu_mapapi_search/flutter_baidu_mapapi_search.dart'
;
import
'package:flutter_bmflocation/flutter_bmflocation.dart'
;
import
'../../map/interface/amap_2d_controller.dart'
;
import
'../../map/poi_search_model.dart'
;
import
'package:getwidget/getwidget.dart'
;
import
'../../routers/fluro_navigator.dart'
;
import
'../../util/toast_utils.dart'
;
class
AddressSelectPage
extends
StatefulWidget
{
const
AddressSelectPage
({
Key
?
key
})
:
super
(
key:
key
);
...
...
@@ -19,13 +20,13 @@ class AddressSelectPage extends StatefulWidget {
}
class
AddressSelectPageState
extends
State
<
AddressSelectPage
>
{
List
<
PoiSearch
>
_list
=
[];
List
<
BMFPoiInfo
>
_list
=
[];
int
_index
=
0
;
final
ScrollController
_controller
=
ScrollController
();
AMap2DController
?
_aMap2DController
;
late
BMFMapController
_myMapController
;
BaiduLocation
_loationResult
=
BaiduLocation
();
BaiduLocation
_lo
c
ationResult
=
BaiduLocation
();
LocationFlutterPlugin
myLocPlugin
=
LocationFlutterPlugin
();
bool
isLoading
=
false
;
@override
void
dispose
()
{
...
...
@@ -46,7 +47,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
///接受定位回调
myLocPlugin
.
singleLocationCallback
(
callback:
(
BaiduLocation
result
)
{
setState
(()
{
_loationResult
=
result
;
_lo
c
ationResult
=
result
;
locationFinish
();
});
});
...
...
@@ -56,7 +57,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
BMFMapSDK
.
setCoordType
(
BMF_COORD_TYPE
.
BD09LL
);
myLocPlugin
.
seriesLocationCallback
(
callback:
(
BaiduLocation
result
)
{
setState
(()
{
_loationResult
=
result
;
_lo
c
ationResult
=
result
;
locationFinish
();
myLocPlugin
.
stopLocation
();
...
...
@@ -64,6 +65,8 @@ class AddressSelectPageState extends State<AddressSelectPage> {
});
}
isLoading
=
true
;
///设置定位参数
_locationAction
();
_startLocation
();
...
...
@@ -77,16 +80,14 @@ class AddressSelectPageState extends State<AddressSelectPage> {
}
///定位完成添加mark
void
locationFinish
()
{
Future
<
void
>
locationFinish
()
async
{
/// 创建BMFMarker
BMFMarker
marker
=
BMFMarker
.
icon
(
position:
BMFCoordinate
(
_lo
ationResult
.
latitude
??
0.0
,
_lo
ationResult
.
longitude
??
0.0
),
_lo
cationResult
.
latitude
??
0.0
,
_loc
ationResult
.
longitude
??
0.0
),
title:
'flutterMaker'
,
identifier:
'flutter_marker'
,
icon:
'assets/images/map/icon_mark.png'
);
print
(
_loationResult
.
latitude
.
toString
()
+
_loationResult
.
longitude
.
toString
());
/// 添加Marker
_myMapController
.
addMarker
(
marker
);
...
...
@@ -94,8 +95,24 @@ class AddressSelectPageState extends State<AddressSelectPage> {
///设置中心点
_myMapController
.
setCenterCoordinate
(
BMFCoordinate
(
_lo
ationResult
.
latitude
??
0.0
,
_lo
ationResult
.
longitude
??
0.0
),
_lo
cationResult
.
latitude
??
0.0
,
_loc
ationResult
.
longitude
??
0.0
),
false
);
// 构造检索参数
BMFPoiNearbySearchOption
poiNearbySearchOption
=
BMFPoiNearbySearchOption
(
keywords:
<
String
>[
'小吃'
,
'学校'
,
'酒店'
,
'公司'
,
'住宅'
],
location:
BMFCoordinate
(
_locationResult
.
latitude
!,
_locationResult
.
longitude
!),
radius:
1000
,
isRadiusLimit:
true
);
BMFPoiNearbySearch
nearbySearch
=
BMFPoiNearbySearch
();
nearbySearch
.
onGetPoiNearbySearchResult
(
callback:
(
BMFPoiSearchResult
result
,
BMFSearchErrorCode
errorCode
)
{
_list
=
result
.
poiInfoList
!;
setState
(()
{});
});
bool
flag
=
await
nearbySearch
.
poiNearbySearch
(
poiNearbySearchOption
);
isLoading
=
false
;
}
/// 设置地图参数
...
...
@@ -155,11 +172,28 @@ class AddressSelectPageState extends State<AddressSelectPage> {
resizeToAvoidBottomInset:
false
,
appBar:
SearchBar
(
hintText:
'搜索地址'
,
onPressed:
(
text
)
{
onPressed:
(
text
)
async
{
_controller
.
animateTo
(
0.0
,
duration:
const
Duration
(
milliseconds:
10
),
curve:
Curves
.
ease
);
_index
=
0
;
_aMap2DController
?.
search
(
text
);
// 构造检索参数
BMFPoiNearbySearchOption
poiNearbySearchOption
=
BMFPoiNearbySearchOption
(
keywords:
<
String
>[
text
],
location:
BMFCoordinate
(
_locationResult
.
latitude
!,
_locationResult
.
longitude
!),
radius:
1000
,
isRadiusLimit:
true
);
BMFPoiNearbySearch
nearbySearch
=
BMFPoiNearbySearch
();
nearbySearch
.
onGetPoiNearbySearchResult
(
callback:
(
BMFPoiSearchResult
result
,
BMFSearchErrorCode
errorCode
)
{
_list
=
result
.
poiInfoList
!;
if
(
_list
.
isEmpty
)
{
Toast
.
show
(
"暂时无法搜索到该位置!"
);
}
setState
(()
{});
});
bool
flag
=
await
nearbySearch
.
poiNearbySearch
(
poiNearbySearchOption
);
},
),
body:
SafeArea
(
...
...
@@ -176,23 +210,45 @@ class AddressSelectPageState extends State<AddressSelectPage> {
),
Expanded
(
flex:
11
,
child:
ListView
.
separated
(
controller:
_controller
,
itemCount:
_list
.
length
,
separatorBuilder:
(
_
,
index
)
=>
const
Divider
(),
itemBuilder:
(
_
,
index
)
{
return
_AddressItem
(
isSelected:
_index
==
index
,
date:
_list
[
index
],
onTap:
()
{
_index
=
index
;
_aMap2DController
?.
move
(
_list
[
index
].
latitude
!,
_list
[
index
].
longitude
!);
setState
(()
{});
},
);
},
),
child:
isLoading
?
const
GFLoader
()
:
ListView
.
separated
(
controller:
_controller
,
itemCount:
_list
.
length
,
separatorBuilder:
(
_
,
index
)
=>
const
Divider
(),
itemBuilder:
(
_
,
index
)
{
return
_AddressItem
(
isSelected:
_index
==
index
,
poi:
_list
[
index
],
onTap:
()
{
_index
=
index
;
_myMapController
.
updateMapOptions
(
BMFMapOptions
(
center:
BMFCoordinate
(
_list
[
index
].
pt
!.
latitude
,
_list
[
index
].
pt
!.
longitude
)));
/// 创建BMFMarker
BMFMarker
marker
=
BMFMarker
.
icon
(
position:
BMFCoordinate
(
_list
[
index
].
pt
!.
latitude
,
_list
[
index
].
pt
!.
longitude
),
title:
'flutterMaker'
,
identifier:
'flutter_marker'
,
icon:
'assets/images/map/icon_mark.png'
);
/// 添加Marker
_myMapController
.
addMarker
(
marker
);
///设置中心点
_myMapController
.
setCenterCoordinate
(
BMFCoordinate
(
_list
[
index
].
pt
!.
latitude
,
_list
[
index
].
pt
!.
longitude
),
false
);
setState
(()
{});
},
);
},
),
),
MyButton
(
onPressed:
()
{
...
...
@@ -214,12 +270,12 @@ class AddressSelectPageState extends State<AddressSelectPage> {
class
_AddressItem
extends
StatelessWidget
{
const
_AddressItem
({
Key
?
key
,
required
this
.
date
,
required
this
.
poi
,
this
.
isSelected
=
false
,
this
.
onTap
,
})
:
super
(
key:
key
);
final
PoiSearch
date
;
final
BMFPoiInfo
poi
;
final
bool
isSelected
;
final
GestureTapCallback
?
onTap
;
...
...
@@ -235,7 +291,7 @@ class _AddressItem extends StatelessWidget {
children:
<
Widget
>[
Expanded
(
child:
Text
(
'
${
date.provinceName!}
${date.cityName!}
${date.adName!}
${date.title!
}
'
,
'
${
poi.province}
${poi.city}
${poi.area}
${poi.name
}
'
,
),
),
Visibility
(
...
...
pubspec.yaml
View file @
6d146bb
...
...
@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version
:
1.0.0+1
0
version
:
1.0.0+1
1
environment
:
sdk
:
"
>=2.16.2
<3.0.0"
...
...
Please
register
or
login
to post a comment