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-10-13 17:57:57 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
26e3041a7de121e3e2549d1848c827f3c53288ba
26e3041a
1 parent
6a91e74d
替换google map
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
266 additions
and
7 deletions
lib/models/nearby_response.dart
lib/poem/page/select_address_page.dart
pubspec.lock
pubspec.yaml
lib/models/nearby_response.dart
0 → 100644
View file @
26e3041
class
NearbyPlacesResponse
{
List
<
Results
>?
results
;
String
?
status
;
NearbyPlacesResponse
({
this
.
results
,
this
.
status
});
NearbyPlacesResponse
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
if
(
json
[
'results'
]
!=
null
)
{
results
=
<
Results
>[];
json
[
'results'
].
forEach
((
v
)
{
results
!.
add
(
Results
.
fromJson
(
v
));
});
}
status
=
json
[
'status'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
Map
<
String
,
dynamic
>();
if
(
this
.
results
!=
null
)
{
data
[
'results'
]
=
this
.
results
!.
map
((
v
)
=>
v
.
toJson
()).
toList
();
}
data
[
'status'
]
=
this
.
status
;
return
data
;
}
}
class
Results
{
Geometry
?
geometry
;
String
?
icon
;
String
?
iconBackgroundColor
;
String
?
iconMaskBaseUri
;
String
?
name
;
List
<
Photos
>?
photos
;
String
?
placeId
;
String
?
reference
;
String
?
scope
;
List
<
String
>?
types
;
String
?
vicinity
;
String
?
businessStatus
;
OpeningHours
?
openingHours
;
PlusCode
?
plusCode
;
dynamic
rating
;
int
?
userRatingsTotal
;
Results
(
{
this
.
geometry
,
this
.
icon
,
this
.
iconBackgroundColor
,
this
.
iconMaskBaseUri
,
this
.
name
,
this
.
photos
,
this
.
placeId
,
this
.
reference
,
this
.
scope
,
this
.
types
,
this
.
vicinity
,
this
.
businessStatus
,
this
.
openingHours
,
this
.
plusCode
,
this
.
rating
,
this
.
userRatingsTotal
});
Results
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
geometry
=
json
[
'geometry'
]
!=
null
?
Geometry
.
fromJson
(
json
[
'geometry'
])
:
null
;
icon
=
json
[
'icon'
];
iconBackgroundColor
=
json
[
'icon_background_color'
];
iconMaskBaseUri
=
json
[
'icon_mask_base_uri'
];
name
=
json
[
'name'
];
if
(
json
[
'photos'
]
!=
null
)
{
photos
=
<
Photos
>[];
json
[
'photos'
].
forEach
((
v
)
{
photos
!.
add
(
Photos
.
fromJson
(
v
));
});
}
placeId
=
json
[
'place_id'
];
reference
=
json
[
'reference'
];
scope
=
json
[
'scope'
];
types
=
json
[
'types'
].
cast
<
String
>();
vicinity
=
json
[
'vicinity'
];
businessStatus
=
json
[
'business_status'
];
openingHours
=
json
[
'opening_hours'
]
!=
null
?
OpeningHours
.
fromJson
(
json
[
'opening_hours'
])
:
null
;
plusCode
=
json
[
'plus_code'
]
!=
null
?
PlusCode
.
fromJson
(
json
[
'plus_code'
])
:
null
;
rating
=
json
[
'rating'
];
userRatingsTotal
=
json
[
'user_ratings_total'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
Map
<
String
,
dynamic
>();
if
(
this
.
geometry
!=
null
)
{
data
[
'geometry'
]
=
this
.
geometry
!.
toJson
();
}
data
[
'icon'
]
=
this
.
icon
;
data
[
'icon_background_color'
]
=
this
.
iconBackgroundColor
;
data
[
'icon_mask_base_uri'
]
=
this
.
iconMaskBaseUri
;
data
[
'name'
]
=
this
.
name
;
if
(
this
.
photos
!=
null
)
{
data
[
'photos'
]
=
this
.
photos
!.
map
((
v
)
=>
v
.
toJson
()).
toList
();
}
data
[
'place_id'
]
=
this
.
placeId
;
data
[
'reference'
]
=
this
.
reference
;
data
[
'scope'
]
=
this
.
scope
;
data
[
'types'
]
=
this
.
types
;
data
[
'vicinity'
]
=
this
.
vicinity
;
data
[
'business_status'
]
=
this
.
businessStatus
;
if
(
this
.
openingHours
!=
null
)
{
data
[
'opening_hours'
]
=
this
.
openingHours
!.
toJson
();
}
if
(
this
.
plusCode
!=
null
)
{
data
[
'plus_code'
]
=
this
.
plusCode
!.
toJson
();
}
data
[
'rating'
]
=
this
.
rating
;
data
[
'user_ratings_total'
]
=
this
.
userRatingsTotal
;
return
data
;
}
}
class
Geometry
{
Location
?
location
;
Viewport
?
viewport
;
Geometry
({
this
.
location
,
this
.
viewport
});
Geometry
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
location
=
json
[
'location'
]
!=
null
?
Location
.
fromJson
(
json
[
'location'
])
:
null
;
viewport
=
json
[
'viewport'
]
!=
null
?
Viewport
.
fromJson
(
json
[
'viewport'
])
:
null
;
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
Map
<
String
,
dynamic
>();
if
(
this
.
location
!=
null
)
{
data
[
'location'
]
=
this
.
location
!.
toJson
();
}
if
(
this
.
viewport
!=
null
)
{
data
[
'viewport'
]
=
this
.
viewport
!.
toJson
();
}
return
data
;
}
}
class
Location
{
double
?
lat
;
double
?
lng
;
Location
({
this
.
lat
,
this
.
lng
});
Location
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
lat
=
json
[
'lat'
];
lng
=
json
[
'lng'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
Map
<
String
,
dynamic
>();
data
[
'lat'
]
=
this
.
lat
;
data
[
'lng'
]
=
this
.
lng
;
return
data
;
}
}
class
Viewport
{
Location
?
northeast
;
Location
?
southwest
;
Viewport
({
this
.
northeast
,
this
.
southwest
});
Viewport
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
northeast
=
json
[
'northeast'
]
!=
null
?
Location
.
fromJson
(
json
[
'northeast'
])
:
null
;
southwest
=
json
[
'southwest'
]
!=
null
?
Location
.
fromJson
(
json
[
'southwest'
])
:
null
;
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
Map
<
String
,
dynamic
>();
if
(
this
.
northeast
!=
null
)
{
data
[
'northeast'
]
=
this
.
northeast
!.
toJson
();
}
if
(
this
.
southwest
!=
null
)
{
data
[
'southwest'
]
=
this
.
southwest
!.
toJson
();
}
return
data
;
}
}
class
Photos
{
int
?
height
;
List
<
String
>?
htmlAttributions
;
String
?
photoReference
;
int
?
width
;
Photos
({
this
.
height
,
this
.
htmlAttributions
,
this
.
photoReference
,
this
.
width
});
Photos
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
height
=
json
[
'height'
];
htmlAttributions
=
json
[
'html_attributions'
].
cast
<
String
>();
photoReference
=
json
[
'photo_reference'
];
width
=
json
[
'width'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
Map
<
String
,
dynamic
>();
data
[
'height'
]
=
this
.
height
;
data
[
'html_attributions'
]
=
this
.
htmlAttributions
;
data
[
'photo_reference'
]
=
this
.
photoReference
;
data
[
'width'
]
=
this
.
width
;
return
data
;
}
}
class
OpeningHours
{
bool
?
openNow
;
OpeningHours
({
this
.
openNow
});
OpeningHours
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
openNow
=
json
[
'open_now'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
Map
<
String
,
dynamic
>();
data
[
'open_now'
]
=
this
.
openNow
;
return
data
;
}
}
class
PlusCode
{
String
?
compoundCode
;
String
?
globalCode
;
PlusCode
({
this
.
compoundCode
,
this
.
globalCode
});
PlusCode
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
compoundCode
=
json
[
'compound_code'
];
globalCode
=
json
[
'global_code'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
Map
<
String
,
dynamic
>();
data
[
'compound_code'
]
=
this
.
compoundCode
;
data
[
'global_code'
]
=
this
.
globalCode
;
return
data
;
}
}
lib/poem/page/select_address_page.dart
View file @
26e3041
import
'dart:async'
;
import
'dart:math'
;
import
'package:location/location.dart'
;
import
'dart:convert'
;
import
'package:Parlando/models/nearby_response.dart'
as
nearby
;
import
'package:flutter/material.dart'
;
import
'package:Parlando/widgets/my_button.dart'
;
import
'package:Parlando/widgets/search_bar.dart'
;
import
'package:getwidget/getwidget.dart'
;
import
'package:google_maps_flutter/google_maps_flutter.dart'
;
import
'../../routers/fluro_navigator.dart'
;
import
'../../util/toast_utils.dart'
;
import
'package:http/http.dart'
as
http
;
import
'package:location/location.dart'
;
class
AddressSelectPage
extends
StatefulWidget
{
const
AddressSelectPage
({
Key
?
key
})
:
super
(
key:
key
);
...
...
@@ -28,6 +26,10 @@ class AddressSelectPageState extends State<AddressSelectPage> {
int
_markerIdCounter
=
1
;
Map
<
MarkerId
,
Marker
>
markers
=
<
MarkerId
,
Marker
>{};
late
StreamSubscription
_locationSubscription
;
String
radius
=
"30"
;
String
apiKey
=
""
;
nearby
.
NearbyPlacesResponse
nearbyPlacesResponse
=
nearby
.
NearbyPlacesResponse
();
@override
void
dispose
()
{
...
...
@@ -44,7 +46,6 @@ class AddressSelectPageState extends State<AddressSelectPage> {
Future
<
void
>
_getCurrentLocation
()
async
{
Location
location
=
Location
();
bool
serviceEnabled
;
PermissionStatus
permissionGranted
;
serviceEnabled
=
await
location
.
serviceEnabled
();
...
...
@@ -68,6 +69,15 @@ class AddressSelectPageState extends State<AddressSelectPage> {
});
}
void
getNearbyPlaces
()
async
{
var
url
=
Uri
.
parse
(
'
${'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${_center.latitude}
,
${_center.longitude}
&radius=
$radius
'
}&
key
=
$apiKey
');
var response = await http.post(url);
nearbyPlacesResponse =
nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body));
setState(() {});
}
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
final String markerIdVal = '
marker_id_$_markerIdCounter
';
...
...
pubspec.lock
View file @
26e3041
This diff is collapsed. Click to expand it.
pubspec.yaml
View file @
26e3041
...
...
@@ -126,6 +126,7 @@ dependencies:
wakelock
:
^0.6.1+2
location
:
^4.4.0
google_maps_flutter
:
^2.1.10
http
:
^0.13.5
dependency_overrides
:
decimal
:
1.5.0
...
...
Please
register
or
login
to post a comment