Google Maps High Billing for Live tracking feature using flutter. How to fix?

Google teams reply:
I have checked our logs and saw spike of usage has a high duplication rate as high as 99.33% (e.g. total request: 16657,Unique request: 112). This indicates that certain application are generating an excessive number of duplicate request, leading to redundant usage of the Directions Api web service/server-side request.

These are data for 4 days of a month where we have tried live tracking.

Now I am sharing my code implementation so that you can get the whole idea.

package use: Location package.
for live tracking I am using firebase to store the data and retrive as Stream.

For Displaying to the user the live tracking am using this code:

 StreamBuilder(
          stream: firestoreInstance
              .collection('location')
              .doc('${widget.dishOrderId}' /*'609'*/)
              .snapshots(),
          builder: (context,
              AsyncSnapshot<DocumentSnapshot<Map<String, dynamic>>> snapshot) {
            if (model.added) {
              updateCamera(snapshot);
            }
            if (!snapshot.hasData) {
              return const Center(child: CircularProgressIndicator());
            }
            return Stack(
              alignment: Alignment.topCenter,
              children: [
                GoogleMap(
                  myLocationButtonEnabled: false,
                  zoomControlsEnabled: false,
                  mapToolbarEnabled: false,
                  initialCameraPosition: model.initialCameraPosition!,
                  onMapCreated: model.onMapCreated,
                  markers: {
                    if (model.origin != null) model.origin!,
                    if (model.destination != null) model.destination!
                  },
                  polylines: {
                    if (model.info != null)
                      Polyline(
                        polylineId: const PolylineId('line'),
                        color: redColor,
                        width: 2,
                        points: model.info!.polylinePoints!
                            .map((e) => LatLng(e.latitude, e.longitude))
                            .toList(),
                      ),
                  },
                ),
                if (model.info != null)
                  Padding(
                    padding: const EdgeInsets.symmetric(
                        vertical: 10, horizontal: 15),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          padding: const EdgeInsets.symmetric(
                              vertical: 4.0, horizontal: 12.0),
                          decoration:
                              bottomConDecoration.copyWith(color: Colors.black),
                          child: Text(
                            '${model.info!.totalDistance}, ${model.info!.totalDuration}',
                            style: const TextStyle(
                                fontSize: 14.0, color: Colors.white),
                          ),
                        ),
                      ],
                    ),
                  ),
              ],
            );
          }),
   

Update Camera Method

Future<void> updateCamera(
      AsyncSnapshot<DocumentSnapshot<Map<String, dynamic>>> snapshot) async {
    model.startMapPosition =
        LatLng(snapshot.data!['latitude'], snapshot.data!['longitude']);
    model.setNewPositions();
  }

Set New Position Method

  void setNewPositions() async {
    final Uint8List markerIcon =
        await getBytesFromAsset('assets/images/delivery_bike.png', 70);
    origin = Marker(
      markerId: const MarkerId('origin'),
      infoWindow: const InfoWindow(title: 'Origin'),
      icon: BitmapDescriptor.fromBytes(markerIcon),
      position: lastMapPosition!,
    );

    destination = Marker(
      markerId: const MarkerId('destination'),
      infoWindow: const InfoWindow(title: 'Destination'),
      icon: BitmapDescriptor.defaultMarker,
      position: startMapPosition!,
    );
    final directions = await DirectionsRepository()
        .getDirections(origin: lastMapPosition, destination: startMapPosition);
    directions.polylinePoints?.insert(
        0, PointLatLng(lastMapPosition!.latitude, lastMapPosition!.longitude));
    info = directions;

    notifyListeners();
  }

Get Directions Method:


 static const String _baseUrl =
      'https://maps.googleapis.com/maps/api/directions/json?';
  Future<Directions> getDirections(
      {LatLng? origin, LatLng? destination}) async {
    final response = await http.get(
      Uri.parse(
          "${_baseUrl}origin=${origin?.latitude},${origin?.longitude}&destination=${destination?.latitude},${destination?.longitude}&key=${URLConstants.googleMapApiKey}"),
    );
    // Check if response is successful
    if (response.statusCode == 200) {
      return Directions.fromMap(jsonDecode(response.body));
    }
    return const Directions();
  }

This is how the directions Api is getting called multiple times in my Project Because of Streams . Now thats why may be I am getting duplicate requests.

If you can tell me what I am doing wrong to minimise the call for directionApi to minimise the bill. I’ll just be bankrupt if this goes on. Your help is much need and urgent .
Please HELP!!! Thanks in advance.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật