Извлечь широту и долготу из Firebase GeoPoint - PullRequest
0 голосов
/ 04 мая 2020

Работая во Flutter, я могу получить доступ к разделам своей базы данных следующим образом:

Streambuilder(
  stream: Firestore.instance.collection('stores').snapshots(),
  builder: (context, snapshot) {
    if (!snapshot.hasData) return CircularProgressIndicator();
    return ListView.builder(
      itemExtent: 60,
      itemCount: snapshot.data.documents.length,
      itemBuilder: (context, index) =>
         _buildListRows(context, snapshot.data.documents[index]),
    );
  }
),

А затем виджет _buildListRows:

Widget _buildListRows(BuildContext context, DocumentSnapshot document) {
    geoPoint = document.reference.firestore.
    return Container(
      height: MediaQuery.of(context).size.height * 0.7,
      child: ListView(
        children: <Widget>[
          Row(
            children: <Widget>[
              Expanded(
                child: Text(
                  'Business Name',
                  style: Theme
                      .of(context)
                      .textTheme
                      .headline,
                ),
              ),
              Container(
                decoration: const BoxDecoration(
                  color: Colors.teal,
                ),
                padding: const EdgeInsets.all(10),
                child: Text(
                  document['store_name'],
                  style: Theme
                      .of(context)
                      .textTheme
                      .display1,
                ),
              ),
            ],
          ),
          Row(
            children: <Widget>[
              Expanded(
                child: Text(
                  'Location',
                  style: Theme
                      .of(context)
                      .textTheme
                      .headline,
                ),
              ),
              Container(
                decoration: const BoxDecoration(
                  color: Colors.teal,
                ),
                padding: const EdgeInsets.all(10),
                child: Text(
                  document['location'].toString(),
                  style: Theme
                      .of(context)
                      .textTheme
                      .display1,
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

Я только начинаю с этого лучший способ получить данные по требованию из базы данных и отобразить их в приложении. Я просто не могу найти нигде, который объясняет, как извлечь долготу и широту из ссылки GeoPoint, возвращенной: document ['location']. ToString (),

Что я получаю из этого вывода:

Instance of 'GeoPoint'

Кроме того, я делаю это правильно? Это лучший способ извлечь данные c из базы данных? Такое чувство, что я делаю это очень неэффективно, но не могу найти другой способ сделать это.

1 Ответ

1 голос
/ 04 мая 2020

Чтобы получить доступ к longitude и latitude, выполните следующие действия:

     child: Text(
                  document['location'].latitude.toString(),
                  style: Theme
                      .of(context)
                      .textTheme
                      .display1,
                ),

Поскольку document['location'] возвращает экземпляр GeoPoint, просто вызовите свойство latitude, чтобы получить значение.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...