ios - Flutter - 使用 google_maps_webservice 和 google_maps_flutter 的附近地点

标签 ios google-maps flutter dart google-places-api

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

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

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

图。 1 下面的上下文,我希望在点击“大本钟”时,我会得到名称、开放时间、评论、图片等。

这将使用 placeId 完成,获取图像的示例如下:https://maps.googleapis.com/maps/api/place/photo?maxwidth =400&photoreference=${photoReference}&key=${kGoogleApiKey}

example map

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

enter image description here

关于ios - Flutter - 使用 google_maps_webservice 和 google_maps_flutter 的附近地点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58107781/

相关文章:

ios - 确保 TextField 实际上包含文本

javascript - 如何使用 Google map 在 ASP MVC 中显示动态位置

dart - sqflite中的多个表

iphone - 相机照片保存在文档文件夹中,并在 iPhone 的桌面 View 中显示名称和 View

ios - 从 NSMutableDictionary 获取 objectAtIndex

javascript - 使用 lat 或 long gmaps v3 删除标记

c# - Visual Studio Visual Studio MVC asp.NET 谷歌地图

loops - 如何在 dart/flutter 中停止/中断 forEach 循环?

dart - 键盘打开时 Flutter 出现溢出错误

ios - TableView 中的两个自定义单元格布局