Flutter - 附近有 google_maps_webservice 和 google_maps_flutter 的地方

Flutter - nearby places with google_maps_webservice and google_maps_flutter

这样做的目的是将用户可以使用股票 google_maps_flutter 插件看到的周围地方变成可点击的标记。单击标记后,用户应该能够看到名称、开放时间、评论、图片等。

我只是无法检索此类数据,并将其显示在 google_maps_flutter 地图上。我还想学习如何输入以英里为单位的半径,所以如果用户只想要一英里以内的地方,他们可以随意选择。

我要的是解释如何获取可变距离内的附近地点数据,以及如何以动态方式将这些地点放在地图上。

图。 1 下面的上下文,我希望在单击 'Big Ben' 时,我会得到名称、开放时间、评论、图片等。

这将使用 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())

我认为该解决方案将修改 答案中的一些代码。

谢谢

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

找到详细解释