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-24 10:33:46 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
81e5f61a9cbbad326e1a8d28b9d3883d648eb796
81e5f61a
1 parent
341fe67b
替换google map
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
5 deletions
lib/poem/page/select_address_page.dart
lib/poem/page/select_address_page.dart
View file @
81e5f61
import
'dart:async'
;
import
'dart:math'
;
import
'package:location/location.dart'
;
import
'package:flutter/material.dart'
;
import
'package:Parlando/widgets/my_button.dart'
;
...
...
@@ -22,10 +25,14 @@ class AddressSelectPageState extends State<AddressSelectPage> {
LatLng
_center
=
const
LatLng
(
45.521563
,
-
122.677433
);
late
GoogleMapController
mapController
;
bool
isLoading
=
false
;
int
_markerIdCounter
=
1
;
Map
<
MarkerId
,
Marker
>
markers
=
<
MarkerId
,
Marker
>{};
late
StreamSubscription
_locationSubscription
;
@override
void
dispose
()
{
_controller
.
dispose
();
_locationSubscription
.
cancel
();
super
.
dispose
();
}
...
...
@@ -40,7 +47,6 @@ class AddressSelectPageState extends State<AddressSelectPage> {
bool
serviceEnabled
;
PermissionStatus
permissionGranted
;
serviceEnabled
=
await
location
.
serviceEnabled
();
if
(!
serviceEnabled
)
{
serviceEnabled
=
await
location
.
requestService
();
...
...
@@ -48,7 +54,6 @@ class AddressSelectPageState extends State<AddressSelectPage> {
return
;
}
}
permissionGranted
=
await
location
.
hasPermission
();
if
(
permissionGranted
==
PermissionStatus
.
denied
)
{
permissionGranted
=
await
location
.
requestPermission
();
...
...
@@ -57,9 +62,25 @@ class AddressSelectPageState extends State<AddressSelectPage> {
}
}
_locationSubscription
=
location
.
onLocationChanged
.
listen
((
LocationData
currentLocation
)
{
// _center = LatLng(currentLocation.latitude!, currentLocation.longitude!);
setState
(()
{});
_center
=
LatLng
(
currentLocation
.
latitude
!,
currentLocation
.
longitude
!);
final
String
markerIdVal
=
'marker_id_
$_markerIdCounter
'
;
_markerIdCounter
++;
final
MarkerId
markerId
=
MarkerId
(
markerIdVal
);
final
Marker
marker
=
Marker
(
markerId:
markerId
,
position:
LatLng
(
currentLocation
.
latitude
!,
currentLocation
.
longitude
!),
);
LatLng
sydney
=
LatLng
(
currentLocation
.
latitude
!,
currentLocation
.
longitude
!);
mapController
.
moveCamera
(
CameraUpdate
.
newLatLng
(
sydney
));
setState
(()
{
markers
[
markerId
]
=
marker
;
});
});
}
...
...
@@ -90,8 +111,9 @@ class AddressSelectPageState extends State<AddressSelectPage> {
onMapCreated:
_onMapCreated
,
initialCameraPosition:
CameraPosition
(
target:
_center
,
zoom:
1
1
.0
,
zoom:
1
6
.0
,
),
markers:
Set
<
Marker
>.
of
(
markers
.
values
),
),
),
Expanded
(
...
...
Please
register
or
login
to post a comment