Я хочу реализовать просмотр карты Google, чтобы получить местоположение, к которому подключаются пользователи

#google-maps #flutter #google-places

#google-карты #flutter #google-places

Вопрос:

В Android я смог вызвать экран Google Places, чтобы позволить пользователю выбрать местоположение для его сохранения, я хочу сделать это с помощью flutter.

Я искал и не нашел почти ничего для реализации этого, и я понял, что теперь это самая официальная библиотека (все еще не реализовано то, что я хочу сделать)https://pub.dartlang.org/packages/google_maps_flutter

и это все еще не закончено (предварительный просмотр для разработчиков)

Ответ №1:

 GoogleMap(
   onTap: _mapTapped,
   compassEnabled: true,
   onMapCreated: makeController,
   initialCameraPosition: CameraPosition(
     target: LatLng(40.712776,-74.005974),
     zoom: 12.0,
   ),
)

_mapTapped(LatLng location) {
   print(location);
// The result will be the location you've been selected 
// something like this LatLng(12.12323,34.12312)
// you can do whatever you do with it

}
  

Ответ №2:

Я использую это в своей pubspec

 map_view: 
    git:
      url: git://github.com/Eimji/flutter_google_map_view
  

Затем вы можете фиксировать события onclick на карте

 mapView.onMapTapped.listen((location) {
      currentLatitude = location.latitude;
      currentLongitude = location.longitude;
      //Show only one marker
      mapView.clearAnnotations();
      mapView.setMarkers(
          [Marker("1", "Location", currentLatitude, currentLongitude)]);
      //Do whatever you want with the chosen location
      mapView.setCameraPosition(
          CameraPosition(Location(currentLatitude, currentLongitude), 18));
      .............
    });