reason

替换google map

class PoiSearch {
PoiSearch({
required this.cityCode,
required this.cityName,
required this.provinceName,
required this.title,
required this.adName,
required this.provinceCode,
required this.latitude,
required this.longitude,
});
PoiSearch.fromJsonMap(Map<String, dynamic> map)
: cityCode = map['cityCode'] as String,
cityName = map['cityName'] as String,
provinceName = map['provinceName'] as String,
title = map['title'] as String,
adName = map['adName'] as String,
provinceCode = map['provinceCode'] as String,
latitude = map['latitude'] as String,
longitude = map['longitude'] as String;
String cityCode;
String cityName;
String provinceName;
String title;
String adName;
String provinceCode;
String latitude;
String longitude;
Map<String, dynamic> toJson() {
final Map<String, dynamic> data = <String, dynamic>{};
data['cityCode'] = cityCode;
data['cityName'] = cityName;
data['provinceName'] = provinceName;
data['title'] = title;
data['adName'] = adName;
data['provinceCode'] = provinceCode;
data['latitude'] = latitude;
data['longitude'] = longitude;
return data;
}
}
import 'package:Parlando/models/nearby_response.dart';
import 'package:Parlando/models/upload_entity.dart';
import 'package:Parlando/net/dio_utils.dart';
import 'package:Parlando/net/http_api.dart';
......@@ -109,12 +110,10 @@ class PoemPublishState extends State<PoemPublish> {
NavigatorUtils.pushResult(
context, PoemRouter.addressSelectPage, (result) {
setState(() {
// final BMFSuggestionInfo model =
// result as BMFSuggestionInfo;
// _longitude = model.location!.longitude.toString();
// _latitude = model.location!.latitude.toString();
// _address =
// '${model.city!} ${model.district!} ${model.address!}';
final Results model = result as Results;
_longitude = model.geometry!.location!.lng.toString();
_latitude = model.geometry!.location!.lat.toString();
_address = '${model.name} ${model.vicinity}';
});
});
},
......@@ -130,10 +129,20 @@ class PoemPublishState extends State<PoemPublish> {
size: 15.px,
),
Gaps.hGap5,
Text(
_address,
style: const TextStyle(color: Colors.black45),
),
Container(
padding: const EdgeInsets.fromLTRB(0, 0, 10, 10),
width: MediaQuery.of(context).size.width * 0.8,
alignment: Alignment.centerLeft,
child: Column(
children: <Widget>[
Text(
_address,
style: const TextStyle(color: Colors.black45),
textAlign: TextAlign.left,
),
],
),
)
],
),
),
......@@ -209,12 +218,12 @@ class PoemPublishState extends State<PoemPublish> {
Gaps.vGap10,
isUploading
? Padding(
padding: const EdgeInsets.all(20),
child: ValueListenableBuilder<double>(
builder: _buildWithValue,
valueListenable: _counter,
),
)
padding: const EdgeInsets.all(20),
child: ValueListenableBuilder<double>(
builder: _buildWithValue,
valueListenable: _counter,
),
)
: Container(),
],
),
......@@ -224,10 +233,10 @@ class PoemPublishState extends State<PoemPublish> {
),
isPublishing
? const Center(
child: CupertinoActivityIndicator(
radius: 16.0,
),
)
child: CupertinoActivityIndicator(
radius: 16.0,
),
)
: Container(),
],
),
......
import 'dart:async';
import 'dart:convert';
import 'package:Parlando/models/nearby_response.dart' as nearby;
import 'package:Parlando/routers/fluro_navigator.dart';
import 'package:Parlando/util/toast_utils.dart';
import 'package:flutter/material.dart';
import 'package:Parlando/widgets/my_button.dart';
import 'package:Parlando/widgets/search_bar.dart';
......@@ -17,7 +19,7 @@ class AddressSelectPage extends StatefulWidget {
}
class AddressSelectPageState extends State<AddressSelectPage> {
// List<BMFSuggestionInfo> _list = [];
List<nearby.Results> _list = [];
int _index = 0;
final ScrollController _controller = ScrollController();
LatLng _center = const LatLng(45.521563, -122.677433);
......@@ -26,8 +28,8 @@ class AddressSelectPageState extends State<AddressSelectPage> {
int _markerIdCounter = 1;
Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
late StreamSubscription _locationSubscription;
String radius = "30";
String apiKey = "";
String radius = "1000";
String apiKey = "AIzaSyDQZsMULyO-UtiSht4_MFi1uHT4BIqasjw";
nearby.NearbyPlacesResponse nearbyPlacesResponse =
nearby.NearbyPlacesResponse();
......@@ -69,13 +71,17 @@ 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');
void getNearbyPlaces(String keyword) async {
String uri =
'${'https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=${_center.latitude},${_center.longitude}&radius=$radius'}&key=$apiKey&keyword=$keyword';
var url = Uri.parse(uri);
var response = await http.post(url);
nearbyPlacesResponse =
nearby.NearbyPlacesResponse.fromJson(jsonDecode(response.body));
setState(() {});
_list = nearbyPlacesResponse.results!;
setState(() {
isLoading = false;
});
}
void _onMapCreated(GoogleMapController controller) {
......@@ -91,6 +97,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
setState(() {
markers[markerId] = marker;
});
getNearbyPlaces("");
}
@override
......@@ -105,6 +112,7 @@ class AddressSelectPageState extends State<AddressSelectPage> {
duration: const Duration(milliseconds: 10), curve: Curves.ease);
_index = 0;
// 构造检索参数
getNearbyPlaces(text);
},
),
body: SafeArea(
......@@ -126,12 +134,13 @@ class AddressSelectPageState extends State<AddressSelectPage> {
child: isLoading
? const GFLoader()
: ListView.separated(
controller: _controller,
itemCount: 1,
controller: _controller,
itemCount: _list.length,
separatorBuilder: (_, index) => const Divider(),
itemBuilder: (_, index) {
return _AddressItem(
isSelected: _index == index,
date: _list[index],
onTap: () {
_index = index;
setState(() {});
......@@ -142,11 +151,11 @@ class AddressSelectPageState extends State<AddressSelectPage> {
),
MyButton(
onPressed: () {
// if (_list.isEmpty) {
// Toast.show('未选择地址!');
// return;
// }
// NavigatorUtils.goBackWithParams(context, _list[_index]);
if (_list.isEmpty) {
Toast.show('未选择地址!');
return;
}
NavigatorUtils.goBackWithParams(context, _list[_index]);
},
text: '确认选择地址',
)
......@@ -160,11 +169,11 @@ class AddressSelectPageState extends State<AddressSelectPage> {
class _AddressItem extends StatelessWidget {
const _AddressItem({
Key? key,
required this.date,
this.isSelected = false,
this.onTap,
}) : super(key: key);
// final BMFSuggestionInfo poi;
final nearby.Results date;
final bool isSelected;
final GestureTapCallback? onTap;
......@@ -178,9 +187,9 @@ class _AddressItem extends StatelessWidget {
height: 50.0,
child: Row(
children: <Widget>[
const Expanded(
Expanded(
child: Text(
'', // '${poi.city} ${poi.district} ${poi.address}',
'${date.name} ${date.vicinity}',
),
),
Visibility(
......
......@@ -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+12
version: 1.0.0+13
environment:
sdk: ">=2.16.2 <3.0.0"
......