matanshukry / flutter_google_places_sdk

Flutter plugin for google places native sdk
32 stars 68 forks source link

InvalidValueError if using findAutocompletePredictions with origin #73

Closed acheronian closed 4 months ago

acheronian commented 4 months ago

Heyo :)

When attempting to use the findAutocompletePredictions method from the flutter_google_places_sdk_web package, an InvalidValueError is thrown. The error message indicates that the origin property is not a valid LatLng or LatLngLiteral object because the lat property is not a number.

Curiously, the issue only occurs sporadically. Sometimes, everything works, sometimes not. Maybe it has something to do with multiple packages using the same google maps javascript skd?

Steps to Reproduce

  1. Call findAutocompletePredictions with an origin parameter that is expected to be a valid LatLng object.
  2. Observe that the error is thrown indicating that the lat property within the origin is not a number.

Expected Behavior

The findAutocompletePredictions method should accept a valid LatLng object without throwing an error.

Actual Behavior

An InvalidValueError is thrown, indicating that the lat property of the origin parameter is not a number.

Environment

Log

API keys were removed postpone.


FlutterGooglePlacesSdk::call error: InvalidValueError: in property origin: not a LatLng or LatLngLiteral with finite coordinates: in property lat: not a number
InvalidValueError: in property origin: not a LatLng or LatLngLiteral with finite coordinates: in property lat: not a number
https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap 204:123  pj
https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap 205:301  <fn>
https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap 57:575   getPlacePredictions
http://localhost:8080/dart-sdk/lib/_internal/js_shared/lib/js_util_patch.dart 110:66                                           callMethod$
http://localhost:8080/packages/google_maps/src/generated/google_maps_places.js.g.dart 889:23                                   AutocompleteService$36Ext.getPlacePredictions
http://localhost:8080/packages/flutter_google_places_sdk_web/flutter_google_places_sdk_web.dart 118:36                         findAutocompletePredictions
http://localhost:8080/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                                       <fn>
http://localhost:8080/dart-sdk/lib/async/zone.dart 1661:54                                                                     runUnary
http://localhost:8080/dart-sdk/lib/async/future_impl.dart 162:18                                                               handleValue
http://localhost:8080/dart-sdk/lib/async/future_impl.dart 846:44                                                               handleValueCallback
http://localhost:8080/dart-sdk/lib/async/future_impl.dart 875:13                                                               _propagateToListeners
http://localhost:8080/dart-sdk/lib/async/future_impl.dart 464:9                                                                callback
http://localhost:8080/dart-sdk/lib/async/schedule_microtask.dart 40:11                                                         _microtaskLoop
http://localhost:8080/dart-sdk/lib/async/schedule_microtask.dart 49:5                                                          _startMicrotaskLoop
http://localhost:8080/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7                                       <fn>
InvalidValueError: in property origin: not a LatLng or LatLngLiteral with finite coordinates: in property lat: not a number
https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap 204:123  pj
https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap 205:301  <fn>
https://maps.googleapis.com/maps/api/js?key=API_KEY&libraries=places&callback=initMap 57:575   getPlacePredictions
http://localhost:8080/dart-sdk/lib/_internal/js_shared/lib/js_util_patch.dart 110:66                                           callMethod$
http://localhost:8080/packages/google_maps/src/generated/google_maps_places.js.g.dart 889:23                                   AutocompleteService$36Ext.getPlacePredictions
http://localhost:8080/packages/flutter_google_places_sdk_web/flutter_google_places_sdk_web.dart 118:36                         findAutocompletePredictions
http://localhost:8080/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                                       <fn>
http://localhost:8080/dart-sdk/lib/async/zone.dart 1661:54                                                                     runUnary
http://localhost:8080/dart-sdk/lib/async/future_impl.dart 162:18                                                               handleValue
http://localhost:8080/dart-sdk/lib/async/future_impl.dart 846:44                                                               handleValueCallback
http://localhost:8080/dart-sdk/lib/async/future_impl.dart 875:13                                                               _propagateToListeners
http://localhost:8080/dart-sdk/lib/async/future_impl.dart 464:9                                                                callback
http://localhost:8080/dart-sdk/lib/async/schedule_microtask.dart 40:11                                                         _microtaskLoop
http://localhost:8080/dart-sdk/lib/async/schedule_microtask.dart 49:5                                                          _startMicrotaskLoop
http://localhost:8080/dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:7                                       <fn>```
matanshukry commented 4 months ago

@acheronian I tried running it multiple times in a row - I don't seem to get that or any error, never.

The web implementation uses the JS web service provided by google JS api, and just provides LatLng to it - I can't think of any reason it would be different suddenly Ref: https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#AutocompletionRequest.origin

Any chance you're passing null to it from time to time, depending on how you use it?

If not, can you create a reproducible example or steps to be used with the example project?

acheronian commented 4 months ago

@matanshukry I've managed to resolve the issue by following the instructions provided in https://github.com/matanshukry/flutter_google_places_sdk/issues/16. It appears there was a specific edge case coupled with google_maps_flutter package that wasn't handled properly in our implementation, which has now been addressed.

Thank you for pointing me in the right direction!