如何打印几个标记Google Map API 0.5.7 Flutter

时间:2019-04-22 20:56:58

标签: google-maps mobile google-maps-api-3 flutter

我正在尝试使用google map api的最新版本(0.5.7),但是在我的地图上仅打印了一个标记,但是数据库上有很多标记,在尝试放置最后一个标记之前,它运行良好版。有人知道如何打印许多标记吗?我在使用标记的地方放了箭头。

import 'package:flutter/material.dart';
import 'package:google_maps_flutter/google_maps_flutter.dart';

import 'package:location/location.dart';

import 'package:geoflutterfire/geoflutterfire.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:rxdart/rxdart.dart';
import 'dart:async';
import 'package:intl/intl.dart';

import 'customs_icons_icons.dart';
import 'Dialogs.dart';
import 'Metro.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        debugShowCheckedModeBanner: false,
        home: Scaffold(
          body: FireMap(),
        ));
  }
}

class FireMap extends StatefulWidget {
  State createState() => FireMapState();
}

class FireMapState extends State<FireMap> {
  GoogleMapController mapController;
  Location location = new Location();
  Dialogs dialogs = new Dialogs();
  Firestore firestore = Firestore.instance;
  Geoflutterfire geo = Geoflutterfire();

  BehaviorSubject<double> radius = BehaviorSubject(seedValue: 100.0);
  Stream<dynamic> query;

  StreamSubscription subscription;`enter code here`

  Map<MarkerId, Marker> markers = <MarkerId, Marker>{};
  MarkerId selectedMarker;
  int _markerIdCounter = 1;

  build(context) {
    return Stack(children: [
      GoogleMap(
        initialCameraPosition:
            CameraPosition(target: LatLng(45.758077, 4.833316), zoom: 15),
        onMapCreated: _onMapCreated,
        myLocationEnabled: true,
        mapType: MapType.normal,
        compassEnabled: true,
        markers: Set<Marker>.of(markers.values),<---
      ),
      Positioned(
        bottom: 20,
        right: 20,
        child: Container(
          height: 80.0,
          width: 80.0,
          child: FittedBox(
            child: FloatingActionButton(
              child: Icon(CustomsIcons.ticket, color: Colors.black),
              backgroundColor: Colors.pink[200],
              onPressed: () => dialogs.information(
                  context, 'Confirmer ?', 'description', addGeoPoint),
            ),
          ),
        ),
      ),
    ]);
  }

  _onMapCreated(GoogleMapController controller) {
    _startQuery();
   setState(
      () {
        mapController = controller;
      },
    );
  }


  void _updateMarkers(List<DocumentSnapshot> documentList) { <---
    final String markerIdVal = 'marker_id_$_markerIdCounter';
    _markerIdCounter++;
    final MarkerId markerId = MarkerId(markerIdVal);
    print(documentList);
    markers.clear();
    documentList.forEach(
      (DocumentSnapshot document) {
        GeoPoint pos = document.data['position']['geopoint'];
        var marker = Marker(
            markerId: markerId,
            position: LatLng(pos.latitude, pos.longitude),
            icon: BitmapDescriptor.fromAsset('assets/ticket_point.png'),
            infoWindow:
                InfoWindow(title: 'Ici à :', snippet: document.data['time']));
        setState(() {
          markers[markerId] = marker;
        });
      },
    );
  }

2 个答案:

答案 0 :(得分:0)

我是这样子的

 $(document).ready(function(){
$("form").submit(function(event){
  var username = $("#username").val();
  var password = $("#password").val();
  var login = $("#login").val();
  $(".formMessage").load("inc/accounts.php",{
    username: username,
    password: password,
    login: login
  });
  event.preventDefault();
 });
});

答案 1 :(得分:0)

有效!我刚刚将markerIDcounter移至“(DocumentSnapshot文档)”中,所有标记均出现