这样做的目的是将用户可以使用股票 google_maps_flutter
插件看到的周围地点变成可点击的标记。单击标记时,用户应该能够看到名称、开放时间、评论、图像等。
我一直坚持检索此类数据,并将其显示在 google_maps_flutter
map 上。我还想学习如何输入以英里为单位的半径,所以如果用户只想要一英里以内的地方,他们可以随意选择。
我要的是解释如何获取可变距离内的附近地点数据,以及如何以动态方式将这些地点放在 map 上。
看图。 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 答案中的一些代码.
谢谢
最佳答案
在ListView中添加一个Card,每行显示地名、地址和类型。顶部的内联 MapView
显示地点的所有图钉标记。当用户点击该行时,应用程序将导航到传递 placeId
的地点详细信息屏幕。
Future<Null> showDetailPlace(String placeId) async {
if (placeId != null) {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => PlaceDetailWidget(placeId)),
);
}
}
class PlaceDetailWidget extends StatefulWidget {
String placeId;
PlaceDetailWidget(String placeId) {
this.placeId = placeId;
}
通过 rajesh muthyala 找到对此的详细解释
关于ios - Flutter - 使用 google_maps_webservice 和 google_maps_flutter 的附近地点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58107781/