Comments (10)
@rscflexible sure, you just need to make sure the GoogleMap widget will be built after the places is initialized. You can use a future builder and the .isInitialized
method with the returned future:
class variables:
late place.FlutterGooglePlacesSdk _places;
late Future _placesInitFuture;
initState:
@override
void initState() {
super.initState();
_places = place.FlutterGooglePlacesSdk('apiKey');
_placesInitFuture = _places.isInitialized();
}
and instead of using GoogleMap
widget directly, use:
FutureBuilder(
future: _placesInitFuture,
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.done) {
return GoogleMap(
myLocationButtonEnabled: false,
initialCameraPosition: CameraPosition(
target: LatLng(lat!, lng!),
),
mapType: MapType.normal,
onMapCreated: _onMapCreate,
myLocationEnabled: false,
);
}
return const CircularProgressIndicator();
},
),
from flutter_google_places_sdk.
@rscflexible Can you provide a reproducible example?
from flutter_google_places_sdk.
When I have google map api key store in project/web/index.html
and I call this function when I press search button in MapScreen
It will show "You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors." in browser console and android studio debug console (But I got the google place predictions result fine)
After that warning when I use move camera function in MapScreen. The camera will not move to target LatLng even if I set fixed LatLng value to it( It works before I call function in second image)
And It will show this error in browser console also
But if I remove google map api key that store in /web/index.html and use function in second image it will not get the errror but then I can't display google map on my MapScreen
Thank you for your fast response.
from flutter_google_places_sdk.
@rscflexible I need a reproducible example - not just screenshots and code snippets. some repository I can clone and run and it will show the same error.
I tried replicating it on my own but it works - I got an index.html file with the added maps/api/js
link like you wrote, and I can still run the search from this package.
from flutter_google_places_sdk.
https://github.com/rscflexible/map_test.git
Your search function work fine here too but somehow I don't know why it make CameraUpdate unusable for me. I can't move camera to other location after use search function.
The problem only occur when you run it for the first time or stop the web and run it again but if you're hot reload it in android studio everything will work fine without warning or error and CameraUpdate will work after use search function
from flutter_google_places_sdk.
@rscflexible I can't get the example to show the map. But either way, why are you trying to insert the <script
tag ?
the web implementation of this package already does that on initialization.
Did you try to just initialize the FlutterGooglePlacesSdk
in initState
, without using the script
tag?
from flutter_google_places_sdk.
If I remove script
tag and add FlutterGooglePlacesSdk(apiKey);
in initState
. The map will not show and throw an exception
The following JSNoSuchMethodError was thrown building GoogleMap(dirty, dependencies: [Directionality], state: _GoogleMapState#0521d): TypeError: Cannot read properties of undefined (reading 'maps') The relevant error-causing widget was: GoogleMap
Could you provide me some example of how to use your package with google_maps_flutter_web
without the need to add script
tag?
from flutter_google_places_sdk.
@matanshukry Your solution is working. Thank you very much for helping me out and for your hard work that you put into this wonderful google place package.
from flutter_google_places_sdk.
@rscflexible you welcome!
from flutter_google_places_sdk.
@rscflexible sure, you just need to make sure the GoogleMap widget will be built after the places is initialized. You can use a future builder and the
.isInitialized
method with the returned future:class variables:
late place.FlutterGooglePlacesSdk _places; late Future _placesInitFuture;
initState:
@override void initState() { super.initState(); _places = place.FlutterGooglePlacesSdk('apiKey'); _placesInitFuture = _places.isInitialized(); }
and instead of using
GoogleMap
widget directly, use:FutureBuilder( future: _placesInitFuture, builder: (context, snapshot) { if (snapshot.connectionState == ConnectionState.done) { return GoogleMap( myLocationButtonEnabled: false, initialCameraPosition: CameraPosition( target: LatLng(lat!, lng!), ), mapType: MapType.normal, onMapCreated: _onMapCreate, myLocationEnabled: false, ); } return const CircularProgressIndicator(); }, ),
This solved my issue. I was having a near identical problem. I was porting my Google Maps implementation to Flutter Web utilizing google_maps_flutter_web.
I fixed it by removing the google_maps_flutter_web
package and line
<script src="https://maps.googleapis.com/maps/api/js?key=YOUR API KEY"></script>
from my index.html file, and following the quoted instructions.
from flutter_google_places_sdk.
Related Issues (20)
- FlutterGooglePlacesSdk::call error: UnimplementedError: initialize() has not been implemented. HOT 4
- Missing ID Field on Place Object Despite Being Listed in PlaceField Enum HOT 3
- Error saying package has missing methods HOT 2
- [BUG] PlusCode can be null HOT 1
- Flutter web deploy issue on aws HOT 1
- Places API (new) HOT 4
- Android: API_ERROR_AUTOCOMPLETE, 9011: This IP, site or mobile application is not authorized to use this API key. HOT 1
- [flutter_google_places_sdk_ios] 0.1.3 contains a breaking change. It should have be versioned as 0.2.0 HOT 4
- Searching for CITIES and ADDRESS in the same placeTypeFilter array returns no results. HOT 1
- error launching on IOS simulator linking in object file HOT 1
- Support JDK 17 HOT 6
- Web release only : crash using findAutocompletePredictions method HOT 3
- InvalidValueError if using findAutocompletePredictions with origin HOT 2
- _places.fetchPlace has work on web debug and not work in release web HOT 2
- Upgrade Google Maps dependency HOT 2
- Google Maps JavaScript API has been loaded directly without loading=async
- Add support for Google Places (new) HOT 2
- web package could use a version bump HOT 1
- Dependencies issues after upgrading to google_maps_flutter 2.6.1 HOT 2
- Support for js ^0.7.1 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_google_places_sdk.