reason

替换google map

1 +class NearbyPlacesResponse {
2 + List<Results>? results;
3 + String? status;
4 +
5 + NearbyPlacesResponse({this.results, this.status});
6 +
7 + NearbyPlacesResponse.fromJson(Map<String, dynamic> json) {
8 + if (json['results'] != null) {
9 + results = <Results>[];
10 + json['results'].forEach((v) {
11 + results!.add(Results.fromJson(v));
12 + });
13 + }
14 + status = json['status'];
15 + }
16 +
17 + Map<String, dynamic> toJson() {
18 + final Map<String, dynamic> data = Map<String, dynamic>();
19 + if (this.results != null) {
20 + data['results'] = this.results!.map((v) => v.toJson()).toList();
21 + }
22 + data['status'] = this.status;
23 + return data;
24 + }
25 +}
26 +
27 +class Results {
28 + Geometry? geometry;
29 + String? icon;
30 + String? iconBackgroundColor;
31 + String? iconMaskBaseUri;
32 + String? name;
33 + List<Photos>? photos;
34 + String? placeId;
35 + String? reference;
36 + String? scope;
37 + List<String>? types;
38 + String? vicinity;
39 + String? businessStatus;
40 + OpeningHours? openingHours;
41 + PlusCode? plusCode;
42 + dynamic rating;
43 + int? userRatingsTotal;
44 +
45 + Results(
46 + {this.geometry,
47 + this.icon,
48 + this.iconBackgroundColor,
49 + this.iconMaskBaseUri,
50 + this.name,
51 + this.photos,
52 + this.placeId,
53 + this.reference,
54 + this.scope,
55 + this.types,
56 + this.vicinity,
57 + this.businessStatus,
58 + this.openingHours,
59 + this.plusCode,
60 + this.rating,
61 + this.userRatingsTotal});
62 +
63 + Results.fromJson(Map<String, dynamic> json) {
64 + geometry =
65 + json['geometry'] != null ? Geometry.fromJson(json['geometry']) : null;
66 + icon = json['icon'];
67 + iconBackgroundColor = json['icon_background_color'];
68 + iconMaskBaseUri = json['icon_mask_base_uri'];
69 + name = json['name'];
70 + if (json['photos'] != null) {
71 + photos = <Photos>[];
72 + json['photos'].forEach((v) {
73 + photos!.add(Photos.fromJson(v));
74 + });
75 + }
76 + placeId = json['place_id'];
77 + reference = json['reference'];
78 + scope = json['scope'];
79 + types = json['types'].cast<String>();
80 + vicinity = json['vicinity'];
81 + businessStatus = json['business_status'];
82 + openingHours = json['opening_hours'] != null
83 + ? OpeningHours.fromJson(json['opening_hours'])
84 + : null;
85 + plusCode =
86 + json['plus_code'] != null ? PlusCode.fromJson(json['plus_code']) : null;
87 + rating = json['rating'];
88 + userRatingsTotal = json['user_ratings_total'];
89 + }
90 +
91 + Map<String, dynamic> toJson() {
92 + final Map<String, dynamic> data = Map<String, dynamic>();
93 + if (this.geometry != null) {
94 + data['geometry'] = this.geometry!.toJson();
95 + }
96 + data['icon'] = this.icon;
97 + data['icon_background_color'] = this.iconBackgroundColor;
98 + data['icon_mask_base_uri'] = this.iconMaskBaseUri;
99 + data['name'] = this.name;
100 + if (this.photos != null) {
101 + data['photos'] = this.photos!.map((v) => v.toJson()).toList();
102 + }
103 + data['place_id'] = this.placeId;
104 + data['reference'] = this.reference;
105 + data['scope'] = this.scope;
106 + data['types'] = this.types;
107 + data['vicinity'] = this.vicinity;
108 + data['business_status'] = this.businessStatus;
109 + if (this.openingHours != null) {
110 + data['opening_hours'] = this.openingHours!.toJson();
111 + }
112 + if (this.plusCode != null) {
113 + data['plus_code'] = this.plusCode!.toJson();
114 + }
115 + data['rating'] = this.rating;
116 + data['user_ratings_total'] = this.userRatingsTotal;
117 + return data;
118 + }
119 +}
120 +
121 +class Geometry {
122 + Location? location;
123 + Viewport? viewport;
124 +
125 + Geometry({this.location, this.viewport});
126 +
127 + Geometry.fromJson(Map<String, dynamic> json) {
128 + location =
129 + json['location'] != null ? Location.fromJson(json['location']) : null;
130 + viewport =
131 + json['viewport'] != null ? Viewport.fromJson(json['viewport']) : null;
132 + }
133 +
134 + Map<String, dynamic> toJson() {
135 + final Map<String, dynamic> data = Map<String, dynamic>();
136 + if (this.location != null) {
137 + data['location'] = this.location!.toJson();
138 + }
139 + if (this.viewport != null) {
140 + data['viewport'] = this.viewport!.toJson();
141 + }
142 + return data;
143 + }
144 +}
145 +
146 +class Location {
147 + double? lat;
148 + double? lng;
149 +
150 + Location({this.lat, this.lng});
151 +
152 + Location.fromJson(Map<String, dynamic> json) {
153 + lat = json['lat'];
154 + lng = json['lng'];
155 + }
156 +
157 + Map<String, dynamic> toJson() {
158 + final Map<String, dynamic> data = Map<String, dynamic>();
159 + data['lat'] = this.lat;
160 + data['lng'] = this.lng;
161 + return data;
162 + }
163 +}
164 +
165 +class Viewport {
166 + Location? northeast;
167 + Location? southwest;
168 +
169 + Viewport({this.northeast, this.southwest});
170 +
171 + Viewport.fromJson(Map<String, dynamic> json) {
172 + northeast =
173 + json['northeast'] != null ? Location.fromJson(json['northeast']) : null;
174 + southwest =
175 + json['southwest'] != null ? Location.fromJson(json['southwest']) : null;
176 + }
177 +
178 + Map<String, dynamic> toJson() {
179 + final Map<String, dynamic> data = Map<String, dynamic>();
180 + if (this.northeast != null) {
181 + data['northeast'] = this.northeast!.toJson();
182 + }
183 + if (this.southwest != null) {
184 + data['southwest'] = this.southwest!.toJson();
185 + }
186 + return data;
187 + }
188 +}
189 +
190 +class Photos {
191 + int? height;
192 + List<String>? htmlAttributions;
193 + String? photoReference;
194 + int? width;
195 +
196 + Photos({this.height, this.htmlAttributions, this.photoReference, this.width});
197 +
198 + Photos.fromJson(Map<String, dynamic> json) {
199 + height = json['height'];
200 + htmlAttributions = json['html_attributions'].cast<String>();
201 + photoReference = json['photo_reference'];
202 + width = json['width'];
203 + }
204 +
205 + Map<String, dynamic> toJson() {
206 + final Map<String, dynamic> data = Map<String, dynamic>();
207 + data['height'] = this.height;
208 + data['html_attributions'] = this.htmlAttributions;
209 + data['photo_reference'] = this.photoReference;
210 + data['width'] = this.width;
211 + return data;
212 + }
213 +}
214 +
215 +class OpeningHours {
216 + bool? openNow;
217 +
218 + OpeningHours({this.openNow});
219 +
220 + OpeningHours.fromJson(Map<String, dynamic> json) {
221 + openNow = json['open_now'];
222 + }
223 +
224 + Map<String, dynamic> toJson() {
225 + final Map<String, dynamic> data = Map<String, dynamic>();
226 + data['open_now'] = this.openNow;
227 + return data;
228 + }
229 +}
230 +
231 +class PlusCode {
232 + String? compoundCode;
233 + String? globalCode;
234 +
235 + PlusCode({this.compoundCode, this.globalCode});
236 +
237 + PlusCode.fromJson(Map<String, dynamic> json) {
238 + compoundCode = json['compound_code'];
239 + globalCode = json['global_code'];
240 + }
241 +
242 + Map<String, dynamic> toJson() {
243 + final Map<String, dynamic> data = Map<String, dynamic>();
244 + data['compound_code'] = this.compoundCode;
245 + data['global_code'] = this.globalCode;
246 + return data;
247 + }
248 +}
1 import 'dart:async'; 1 import 'dart:async';
2 -import 'dart:math'; 2 +import 'dart:convert';
3 - 3 +import 'package:Parlando/models/nearby_response.dart' as nearby;
4 -import 'package:location/location.dart';
5 import 'package:flutter/material.dart'; 4 import 'package:flutter/material.dart';
6 import 'package:Parlando/widgets/my_button.dart'; 5 import 'package:Parlando/widgets/my_button.dart';
7 import 'package:Parlando/widgets/search_bar.dart'; 6 import 'package:Parlando/widgets/search_bar.dart';
8 import 'package:getwidget/getwidget.dart'; 7 import 'package:getwidget/getwidget.dart';
9 import 'package:google_maps_flutter/google_maps_flutter.dart'; 8 import 'package:google_maps_flutter/google_maps_flutter.dart';
10 - 9 +import 'package:http/http.dart' as http;
11 -import '../../routers/fluro_navigator.dart'; 10 +import 'package:location/location.dart';
12 -import '../../util/toast_utils.dart';
13 11
14 class AddressSelectPage extends StatefulWidget { 12 class AddressSelectPage extends StatefulWidget {
15 const AddressSelectPage({Key? key}) : super(key: key); 13 const AddressSelectPage({Key? key}) : super(key: key);
...@@ -28,6 +26,10 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -28,6 +26,10 @@ class AddressSelectPageState extends State<AddressSelectPage> {
28 int _markerIdCounter = 1; 26 int _markerIdCounter = 1;
29 Map<MarkerId, Marker> markers = <MarkerId, Marker>{}; 27 Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
30 late StreamSubscription _locationSubscription; 28 late StreamSubscription _locationSubscription;
29 + String radius = "30";
30 + String apiKey = "";
31 + nearby.NearbyPlacesResponse nearbyPlacesResponse =
32 + nearby.NearbyPlacesResponse();
31 33
32 @override 34 @override
33 void dispose() { 35 void dispose() {
...@@ -44,7 +46,6 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -44,7 +46,6 @@ class AddressSelectPageState extends State<AddressSelectPage> {
44 46
45 Future<void> _getCurrentLocation() async { 47 Future<void> _getCurrentLocation() async {
46 Location location = Location(); 48 Location location = Location();
47 -
48 bool serviceEnabled; 49 bool serviceEnabled;
49 PermissionStatus permissionGranted; 50 PermissionStatus permissionGranted;
50 serviceEnabled = await location.serviceEnabled(); 51 serviceEnabled = await location.serviceEnabled();
...@@ -68,6 +69,15 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -68,6 +69,15 @@ class AddressSelectPageState extends State<AddressSelectPage> {
68 }); 69 });
69 } 70 }
70 71
72 + void getNearbyPlaces() async {
73 + var url = Uri.parse(
74 + '${'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${_center.latitude},${_center.longitude}&radius=$radius'}&key=$apiKey');
75 + var response = await http.post(url);
76 + nearbyPlacesResponse =
77 + nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body));
78 + setState(() {});
79 + }
80 +
71 void _onMapCreated(GoogleMapController controller) { 81 void _onMapCreated(GoogleMapController controller) {
72 mapController = controller; 82 mapController = controller;
73 final String markerIdVal = 'marker_id_$_markerIdCounter'; 83 final String markerIdVal = 'marker_id_$_markerIdCounter';
......
This diff is collapsed. Click to expand it.
...@@ -126,6 +126,7 @@ dependencies: ...@@ -126,6 +126,7 @@ dependencies:
126 wakelock: ^0.6.1+2 126 wakelock: ^0.6.1+2
127 location: ^4.4.0 127 location: ^4.4.0
128 google_maps_flutter: ^2.1.10 128 google_maps_flutter: ^2.1.10
129 + http: ^0.13.5
129 130
130 dependency_overrides: 131 dependency_overrides:
131 decimal: 1.5.0 132 decimal: 1.5.0
......