fluttercommunity / firestore_helpers

Firestore Helpers - Firestore helper function to create dynamic and location based queries. Maintainer: @escamoteur
https://pub.dev/packages/firestore_helpers
MIT License
48 stars 19 forks source link

Geoquery: the distance is not correct, the query find item out of area! #1

Closed juani21 closed 6 years ago

juani21 commented 6 years ago

Hi , i use this code for location query. The result is not correct because it find location out of range and the distances are wrong. i check with google maps the distance between the point of Area and the points of firestore.

`static Stream<List> getEvents() {

Area area = new Area(new GeoPoint(42.324322, 13.7075033), 0.7);
try {
  return getDataInArea(
      area: area,
      collection: reference,
      locationFieldNameInDB: 'position',
      mapper: (eventDoc) {
        var event = Event.fromMap(eventDoc.data);
        return new EventData(event);
      },
      locationAccessor: (eventData) => eventData.event.location,
      distanceMapper: (eventData, distance) {
        eventData.distance = distance;
        return eventData;
      },
      distanceAccessor: (eventData) => eventData.distance, // filer only future events
  );
} on Exception catch (ex) {
  print(ex);
}
return null;

} }` How can i fix? it s a bug?

thank you

escamoteur commented 6 years ago

Hi, FireStore isn't able to search in a real circle. It searches in a square fully containing the given circle. So it might return places in the corners of the square that are further away than radius.

escamoteur commented 6 years ago

But thinkin a bit mor about is I can filterout these places on the client side

juani21 commented 6 years ago

I understand but the query result is out of range of the square.... :(

escamoteur commented 6 years ago

really how much off?

juani21 commented 6 years ago

I'm looking for positions that are 0.7 km away from me but the result is far 1.5 km and the distances are not correct.... i m try again ....

escamoteur commented 6 years ago

@juani21 I think I might found some error I will make a correction, stay tuned

escamoteur commented 6 years ago

@juani21 could you try

firestore_helpers: "2.0.1+dev"

escamoteur commented 6 years ago

sorry meant firestore_helpers: "2.0.1+dev1"

juani21 commented 6 years ago

Now i have this error:

The method 'insert' was called on null. I/flutter ( 7759): Receiver: null I/flutter ( 7759): Tried calling: insert(0, Closure: (T) => bool) I/flutter ( 7759): I/flutter ( 7759): When the exception was thrown, this was the stack: I/flutter ( 7759): #0 Object.noSuchMethod (dart:core/runtime/libobject_patch.dart:46:5) I/flutter ( 7759): #1 getDataInArea (package:firestore_helpers/src/geo_helpers.dart:251:45) I/flutter ( 7759): #2 Utils.getEvents (package:gmdfprenotation/utils.dart:282:14) I/flutter ( 7759): #3 UserPage.buildList (package:gmdfprenotation/page/user_profile.dart:23:21) I/flutter ( 7759): #4 UserPage.build (package:gmdfprenotation/page/user_profile.dart:14:13) I/flutter ( 7759): #5 StatelessElement.build (package:flutter/src/widgets/framework.dart:3695:28) I/flutter ( 7759): #6 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3642:15) I/flutter ( 7759): #7 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #8 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #9 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #10 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #11 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #12 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14) I/flutter ( 7759): #13 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #14 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #15 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #16 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #17 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #18 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #19 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #20 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #21 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14) I/flutter ( 7759): #22 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #23 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #24 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14) I/flutter ( 7759): #25 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #26 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #27 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14) I/flutter ( 7759): #28 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #29 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #30 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14) I/flutter ( 7759): #31 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #32 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #33 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #34 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #35 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #36 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3769:11) I/flutter ( 7759): #37 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #38 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #39 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #40 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #41 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #42 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #43 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #44 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #45 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #46 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #47 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #48 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #49 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3769:11) I/flutter ( 7759): #50 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #51 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #52 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #53 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14) I/flutter ( 7759): #54 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #55 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #56 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #57 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #58 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #59 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #60 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #61 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #62 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14) I/flutter ( 7759): #63 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #64 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #65 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #66 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #67 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #68 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3769:11) I/flutter ( 7759): #69 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #70 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #71 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #72 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #73 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #74 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #75 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #76 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #77 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #78 SingleChildRenderObjectElement.mount (package:flutter/src/widgets/framework.dart:4654:14) I/flutter ( 7759): #79 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #80 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #81 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #82 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #83 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #84 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #85 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #86 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #87 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #88 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #89 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #90 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3769:11) I/flutter ( 7759): #91 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #92 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #93 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #94 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #95 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #96 ComponentElement._firstBuild (package:flutter/src/widgets/framework.dart:3622:5) I/flutter ( 7759): #97 StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3769:11) I/flutter ( 7759): #98 ComponentElement.mount (package:flutter/src/widgets/framework.dart:3617:5) I/flutter ( 7759): #99 Element.inflateWidget (package:flutter/src/widgets/framework.dart:2907:14) I/flutter ( 7759): #100 Element.updateChild (package:flutter/src/widgets/framework.dart:2710:12) I/flutter ( 7759): #101 RenderObjectElement.updateChildren (package:flutter/src/widgets/framework.dart:4437:32) I/flutter ( 7759): #102 MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4769:17) I/flutter ( 7759): #103 Element.updateChild (package:flutter/src/widgets/framework.dart:2699:15) I/flutter ( 7759): #104 _TheatreElement.update (package:flutter/src/widgets/overlay.dart:507:16) I/flutter ( 7759): #105 Element.updateChild (package:flutter/src/widgets/framework.dart:2699:15) I/flutter ( 7759): #106 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #107 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #108 StatefulElement.update (package:flutter/src/widgets/framework.dart:3799:5) I/flutter ( 7759): #109 Element.updateChild (package:flutter/src/widgets/framework.dart:2699:15) I/flutter ( 7759): #110 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #111 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #112 ProxyElement.update (package:flutter/src/widgets/framework.dart:3909:5) I/flutter ( 7759): #113 Element.updateChild (package:flutter/src/widgets/framework.dart:2699:15) I/flutter ( 7759): #114 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4661:14) I/flutter ( 7759): #115 Element.updateChild (package:flutter/src/widgets/framework.dart:2699:15) I/flutter ( 7759): #116 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #117 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #118 StatefulElement.update (package:flutter/src/widgets/framework.dart:3799:5) I/flutter ( 7759): #119 Element.updateChild (package:flutter/src/widgets/framework.dart:2699:15) I/flutter ( 7759): #120 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4661:14) I/flutter ( 7759): #121 Element.updateChild (package:flutter/src/widgets/framework.dart:2699:15) I/flutter ( 7759): #122 SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:4661:14) I/flutter ( 7759): #123 Element.updateChild (package:flutter/src/widgets/framework.dart:2699:15) I/flutter ( 7759): #124 ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:3653:16) I/flutter ( 7759): #125 Element.rebuild (package:flutter/src/widgets/framework.dart:3495:5) I/flutter ( 7759): #126 BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2242:33) I/flutter ( 7759): #127 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:626:20) I/flutter ( 7759): #128 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:208:5) I/flutter ( 7759): #129 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:990:15) I/flutter ( 7759): #130 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:930:9) I/flutter ( 7759): #131 _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:842:5) I/flutter ( 7759): #132 _invoke (dart:ui/hooks.dart:120:13) I/flutter ( 7759): #133 _drawFrame (dart:ui/hooks.dart:109:3)

escamoteur commented 6 years ago

uups, yes sorry I know what the probelms is give me a minute

escamoteur commented 6 years ago

could you try

firestore_helpers: "2.0.1+dev2"

escamoteur commented 6 years ago

@juani21 does it work?

juani21 commented 6 years ago

the error there is not anymore... now i haven t result but is my fault maybe

juani21 commented 6 years ago

i try to create new collection in firestore and i have a result, in previuos collection i haven t .,.... i don't know if there a problem with query... i continue to try

juani21 commented 6 years ago

@escamoteur between different points i retrieve only the point equal to center of area

escamoteur commented 6 years ago

Uuh sorry may I put a == instead of a <=. Will be back at my desk in half an hour

escamoteur commented 6 years ago

HI could we continue this on GItter? https://gitter.im/flutter/flutter

escamoteur commented 6 years ago

Could you please test 2.0.1+dev3

escamoteur commented 6 years ago

Fixed with V2.02