reason

替换google map

1 +class PoiSearch {
2 + PoiSearch({
3 + required this.cityCode,
4 + required this.cityName,
5 + required this.provinceName,
6 + required this.title,
7 + required this.adName,
8 + required this.provinceCode,
9 + required this.latitude,
10 + required this.longitude,
11 + });
12 +
13 + PoiSearch.fromJsonMap(Map<String, dynamic> map)
14 + : cityCode = map['cityCode'] as String,
15 + cityName = map['cityName'] as String,
16 + provinceName = map['provinceName'] as String,
17 + title = map['title'] as String,
18 + adName = map['adName'] as String,
19 + provinceCode = map['provinceCode'] as String,
20 + latitude = map['latitude'] as String,
21 + longitude = map['longitude'] as String;
22 +
23 + String cityCode;
24 + String cityName;
25 + String provinceName;
26 + String title;
27 + String adName;
28 + String provinceCode;
29 + String latitude;
30 + String longitude;
31 +
32 + Map<String, dynamic> toJson() {
33 + final Map<String, dynamic> data = <String, dynamic>{};
34 + data['cityCode'] = cityCode;
35 + data['cityName'] = cityName;
36 + data['provinceName'] = provinceName;
37 + data['title'] = title;
38 + data['adName'] = adName;
39 + data['provinceCode'] = provinceCode;
40 + data['latitude'] = latitude;
41 + data['longitude'] = longitude;
42 + return data;
43 + }
44 +}
1 +import 'package:Parlando/models/nearby_response.dart';
1 import 'package:Parlando/models/upload_entity.dart'; 2 import 'package:Parlando/models/upload_entity.dart';
2 import 'package:Parlando/net/dio_utils.dart'; 3 import 'package:Parlando/net/dio_utils.dart';
3 import 'package:Parlando/net/http_api.dart'; 4 import 'package:Parlando/net/http_api.dart';
...@@ -109,12 +110,10 @@ class PoemPublishState extends State<PoemPublish> { ...@@ -109,12 +110,10 @@ class PoemPublishState extends State<PoemPublish> {
109 NavigatorUtils.pushResult( 110 NavigatorUtils.pushResult(
110 context, PoemRouter.addressSelectPage, (result) { 111 context, PoemRouter.addressSelectPage, (result) {
111 setState(() { 112 setState(() {
112 - // final BMFSuggestionInfo model = 113 + final Results model = result as Results;
113 - // result as BMFSuggestionInfo; 114 + _longitude = model.geometry!.location!.lng.toString();
114 - // _longitude = model.location!.longitude.toString(); 115 + _latitude = model.geometry!.location!.lat.toString();
115 - // _latitude = model.location!.latitude.toString(); 116 + _address = '${model.name} ${model.vicinity}';
116 - // _address =
117 - // '${model.city!} ${model.district!} ${model.address!}';
118 }); 117 });
119 }); 118 });
120 }, 119 },
...@@ -130,10 +129,20 @@ class PoemPublishState extends State<PoemPublish> { ...@@ -130,10 +129,20 @@ class PoemPublishState extends State<PoemPublish> {
130 size: 15.px, 129 size: 15.px,
131 ), 130 ),
132 Gaps.hGap5, 131 Gaps.hGap5,
133 - Text( 132 + Container(
134 - _address, 133 + padding: const EdgeInsets.fromLTRB(0, 0, 10, 10),
135 - style: const TextStyle(color: Colors.black45), 134 + width: MediaQuery.of(context).size.width * 0.8,
136 - ), 135 + alignment: Alignment.centerLeft,
136 + child: Column(
137 + children: <Widget>[
138 + Text(
139 + _address,
140 + style: const TextStyle(color: Colors.black45),
141 + textAlign: TextAlign.left,
142 + ),
143 + ],
144 + ),
145 + )
137 ], 146 ],
138 ), 147 ),
139 ), 148 ),
...@@ -209,12 +218,12 @@ class PoemPublishState extends State<PoemPublish> { ...@@ -209,12 +218,12 @@ class PoemPublishState extends State<PoemPublish> {
209 Gaps.vGap10, 218 Gaps.vGap10,
210 isUploading 219 isUploading
211 ? Padding( 220 ? Padding(
212 - padding: const EdgeInsets.all(20), 221 + padding: const EdgeInsets.all(20),
213 - child: ValueListenableBuilder<double>( 222 + child: ValueListenableBuilder<double>(
214 - builder: _buildWithValue, 223 + builder: _buildWithValue,
215 - valueListenable: _counter, 224 + valueListenable: _counter,
216 - ), 225 + ),
217 - ) 226 + )
218 : Container(), 227 : Container(),
219 ], 228 ],
220 ), 229 ),
...@@ -224,10 +233,10 @@ class PoemPublishState extends State<PoemPublish> { ...@@ -224,10 +233,10 @@ class PoemPublishState extends State<PoemPublish> {
224 ), 233 ),
225 isPublishing 234 isPublishing
226 ? const Center( 235 ? const Center(
227 - child: CupertinoActivityIndicator( 236 + child: CupertinoActivityIndicator(
228 - radius: 16.0, 237 + radius: 16.0,
229 - ), 238 + ),
230 - ) 239 + )
231 : Container(), 240 : Container(),
232 ], 241 ],
233 ), 242 ),
......
1 import 'dart:async'; 1 import 'dart:async';
2 import 'dart:convert'; 2 import 'dart:convert';
3 import 'package:Parlando/models/nearby_response.dart' as nearby; 3 import 'package:Parlando/models/nearby_response.dart' as nearby;
4 +import 'package:Parlando/routers/fluro_navigator.dart';
5 +import 'package:Parlando/util/toast_utils.dart';
4 import 'package:flutter/material.dart'; 6 import 'package:flutter/material.dart';
5 import 'package:Parlando/widgets/my_button.dart'; 7 import 'package:Parlando/widgets/my_button.dart';
6 import 'package:Parlando/widgets/search_bar.dart'; 8 import 'package:Parlando/widgets/search_bar.dart';
...@@ -17,7 +19,7 @@ class AddressSelectPage extends StatefulWidget { ...@@ -17,7 +19,7 @@ class AddressSelectPage extends StatefulWidget {
17 } 19 }
18 20
19 class AddressSelectPageState extends State<AddressSelectPage> { 21 class AddressSelectPageState extends State<AddressSelectPage> {
20 - // List<BMFSuggestionInfo> _list = []; 22 + List<nearby.Results> _list = [];
21 int _index = 0; 23 int _index = 0;
22 final ScrollController _controller = ScrollController(); 24 final ScrollController _controller = ScrollController();
23 LatLng _center = const LatLng(45.521563, -122.677433); 25 LatLng _center = const LatLng(45.521563, -122.677433);
...@@ -26,8 +28,8 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -26,8 +28,8 @@ class AddressSelectPageState extends State<AddressSelectPage> {
26 int _markerIdCounter = 1; 28 int _markerIdCounter = 1;
27 Map<MarkerId, Marker> markers = <MarkerId, Marker>{}; 29 Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
28 late StreamSubscription _locationSubscription; 30 late StreamSubscription _locationSubscription;
29 - String radius = "30"; 31 + String radius = "1000";
30 - String apiKey = ""; 32 + String apiKey = "AIzaSyDQZsMULyO-UtiSht4_MFi1uHT4BIqasjw";
31 nearby.NearbyPlacesResponse nearbyPlacesResponse = 33 nearby.NearbyPlacesResponse nearbyPlacesResponse =
32 nearby.NearbyPlacesResponse(); 34 nearby.NearbyPlacesResponse();
33 35
...@@ -69,13 +71,17 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -69,13 +71,17 @@ class AddressSelectPageState extends State<AddressSelectPage> {
69 }); 71 });
70 } 72 }
71 73
72 - void getNearbyPlaces() async { 74 + void getNearbyPlaces(String keyword) async {
73 - var url = Uri.parse( 75 + String uri =
74 - '${'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${_center.latitude},${_center.longitude}&radius=$radius'}&key=$apiKey'); 76 + '${'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${_center.latitude},${_center.longitude}&radius=$radius'}&key=$apiKey&keyword=$keyword';
77 + var url = Uri.parse(uri);
75 var response = await http.post(url); 78 var response = await http.post(url);
76 nearbyPlacesResponse = 79 nearbyPlacesResponse =
77 nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body)); 80 nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body));
78 - setState(() {}); 81 + _list = nearbyPlacesResponse.results!;
82 + setState(() {
83 + isLoading = false;
84 + });
79 } 85 }
80 86
81 void _onMapCreated(GoogleMapController controller) { 87 void _onMapCreated(GoogleMapController controller) {
...@@ -91,6 +97,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -91,6 +97,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
91 setState(() { 97 setState(() {
92 markers[markerId] = marker; 98 markers[markerId] = marker;
93 }); 99 });
100 + getNearbyPlaces("");
94 } 101 }
95 102
96 @override 103 @override
...@@ -105,6 +112,7 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -105,6 +112,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
105 duration: const Duration(milliseconds: 10), curve: Curves.ease); 112 duration: const Duration(milliseconds: 10), curve: Curves.ease);
106 _index = 0; 113 _index = 0;
107 // 构造检索参数 114 // 构造检索参数
115 + getNearbyPlaces(text);
108 }, 116 },
109 ), 117 ),
110 body: SafeArea( 118 body: SafeArea(
...@@ -126,12 +134,13 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -126,12 +134,13 @@ class AddressSelectPageState extends State<AddressSelectPage> {
126 child: isLoading 134 child: isLoading
127 ? const GFLoader() 135 ? const GFLoader()
128 : ListView.separated( 136 : ListView.separated(
129 - controller: _controller, 137 + controller: _controller,
130 - itemCount: 1, 138 + itemCount: _list.length,
131 separatorBuilder: (_, index) => const Divider(), 139 separatorBuilder: (_, index) => const Divider(),
132 itemBuilder: (_, index) { 140 itemBuilder: (_, index) {
133 return _AddressItem( 141 return _AddressItem(
134 isSelected: _index == index, 142 isSelected: _index == index,
143 + date: _list[index],
135 onTap: () { 144 onTap: () {
136 _index = index; 145 _index = index;
137 setState(() {}); 146 setState(() {});
...@@ -142,11 +151,11 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -142,11 +151,11 @@ class AddressSelectPageState extends State<AddressSelectPage> {
142 ), 151 ),
143 MyButton( 152 MyButton(
144 onPressed: () { 153 onPressed: () {
145 - // if (_list.isEmpty) { 154 + if (_list.isEmpty) {
146 - // Toast.show('未选择地址!'); 155 + Toast.show('未选择地址!');
147 - // return; 156 + return;
148 - // } 157 + }
149 - // NavigatorUtils.goBackWithParams(context, _list[_index]); 158 + NavigatorUtils.goBackWithParams(context, _list[_index]);
150 }, 159 },
151 text: '确认选择地址', 160 text: '确认选择地址',
152 ) 161 )
...@@ -160,11 +169,11 @@ class AddressSelectPageState extends State<AddressSelectPage> { ...@@ -160,11 +169,11 @@ class AddressSelectPageState extends State<AddressSelectPage> {
160 class _AddressItem extends StatelessWidget { 169 class _AddressItem extends StatelessWidget {
161 const _AddressItem({ 170 const _AddressItem({
162 Key? key, 171 Key? key,
172 + required this.date,
163 this.isSelected = false, 173 this.isSelected = false,
164 this.onTap, 174 this.onTap,
165 }) : super(key: key); 175 }) : super(key: key);
166 - 176 + final nearby.Results date;
167 - // final BMFSuggestionInfo poi;
168 final bool isSelected; 177 final bool isSelected;
169 final GestureTapCallback? onTap; 178 final GestureTapCallback? onTap;
170 179
...@@ -178,9 +187,9 @@ class _AddressItem extends StatelessWidget { ...@@ -178,9 +187,9 @@ class _AddressItem extends StatelessWidget {
178 height: 50.0, 187 height: 50.0,
179 child: Row( 188 child: Row(
180 children: <Widget>[ 189 children: <Widget>[
181 - const Expanded( 190 + Expanded(
182 child: Text( 191 child: Text(
183 - '', // '${poi.city} ${poi.district} ${poi.address}', 192 + '${date.name} ${date.vicinity}',
184 ), 193 ),
185 ), 194 ),
186 Visibility( 195 Visibility(
......
...@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev ...@@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
15 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. 15 # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
16 # Read more about iOS versioning at 16 # Read more about iOS versioning at
17 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html 17 # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
18 -version: 1.0.0+12 18 +version: 1.0.0+13
19 19
20 environment: 20 environment:
21 sdk: ">=2.16.2 <3.0.0" 21 sdk: ">=2.16.2 <3.0.0"
......