【发布时间】:2020-01-26 04:48:11
【问题描述】:
这样做的目的是将用户可以使用 stock google_maps_flutter 插件在他们周围看到的地方变成可点击的标记。单击标记后,用户应该能够看到名称、开放时间、评论、图像等。
我只是坚持检索这种数据,并将其显示在google_maps_flutter 地图上。我还想学习如何以英里为单位输入半径,所以如果用户只想要一英里内的地方,他们可以随意选择。
我要解释的是如何在可变距离内获取附近的地点数据,以及如何以动态方式将这些地点放在地图上。
看图。 1 下面的上下文,我可以预期在点击“大本钟”时,我会得到名字、开放时间、评论、图片等。
这将使用placeId 完成,获取图像的示例类似于:https://maps.googleapis.com/maps/api/place/photo?maxwidth=400&photoreference=${photoReference}&key=${kGoogleApiKey}。
图 1。
编辑:
在玩了 Sreerams 的结论之后,我得到的是这个而不是附近的每个地方:
Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult', Instance of 'PlacesSearchResult'
这是我用来检索这些数据的:
static String kGoogleApiKey = 'myKey';
GoogleMapsPlaces _places = GoogleMapsPlaces(apiKey: kGoogleApiKey);
List<PlacesSearchResult> places = [];
void _onMapCreated(GoogleMapController controller) {
mapController = controller;
getNearbyPlaces(LatLng(lat,lng));
}
void getNearbyPlaces(LatLng center) async {
final location = Location(lat, lng);
final result = await _places.searchNearbyWithRadius(location, 2500);
setState(() {
if (result.status == "OK") {
this.places = result.results;
}
print(result.status);
});
}
这是我用来显示这些数据的:
Text(places[i].toString())
我假设该解决方案将修改this question 的答案中的一些代码。
谢谢
【问题讨论】:
标签: ios google-maps flutter dart google-places-api