【问题标题】:Flutter - nearby places with google_maps_webservice and google_maps_flutterFlutter - 附近有 google_maps_webservice 和 google_maps_flutter 的地方
【发布时间】: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


    【解决方案1】:

    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找到对此的详细解释

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-11
      • 2012-06-10
      • 2015-04-23
      • 1970-01-01
      • 2015-09-10
      • 1970-01-01
      相关资源
      最近更新 更多