-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors #89
Comments
I have the same problem when I use it in conjunction with the react-google-places-autocomplete library |
I have the same problem when i use with react-google-autocomplete |
@adrielgro @claudiomnec @benderlidze Hi! I've just released a new version(v2) which should fix that issue. Please let me know if you still encounter it. Thanks! |
Hey @ErrorPro! Got something related to this issue. I am using:
The error I'm getting is: Ofc, once the map is removed from the same page - the autocomplete works properly! |
hey @pekac ! Thanks for your message. We tried to reproduce the issue but unfortunately, we could not. Could you add some more info or show/send the piece of code how you are using it? |
Hey @ErrorPro ! Thanks for looking into it so deeply!
Definitely looks that way. Give me some time to spin up a min-reproducible repo. I believe this will be the easiest way to pinpoint the issue. |
✋🏽 Same here. Using:
You have included the Google Maps JavaScript API multiple times on this page.
This may cause unexpected errors.
Uncaught (in promise) TypeError: Cannot read property 'um' of undefined |
@thebiltheory Hey, is it possible to share a piece of code(if it's the same component). I want to understand the flow, which lib first gets to load google API, thanks! P.S. I have some ideas about what might cause it and I am checking it out |
I just found out the way to reproduce it. The problem is that autocomplete library needs
|
If you're using this package alongside with
|
How? @GarryOne |
@izzyworks89 You could try by setting the API key and the places library by using the
|
Use this code And when rendering Autocomplete, Please enclose Autocomplete in |
Hi guys! |
One thing to be aware of that even with useLoadScript, you have to make sure that both urls are identical, i.e. contain the same parameters in the same order. I recommend loading the script in a separate component
|
If using one of the loaders you will need to do a check to see if google maps is already loaded and then use the already existing instance, and you will also need to check to see if the loader exists so that you can wait for the scripts to finish loading before trying again. Here is my code, hope this helps someone who is as lost as I was lol. ^_^ sleep(ms) {
return new Promise((resolve) => setTimeout(resolve, ms));
}
async loadGoogleMaps(options?: LoaderOptions) {
if (window?.google) return window.google;
if ((window as any)?._dk_google_maps_loader_cb) {
await this.sleep(200);
return this.loadGoogleMaps();
}
try {
const loader = new Loader(this.googleMapsKey, {
libraries: ["places"],
...options,
});
return loader.load();
} catch (e) {
console.log(e);
setTimeout(this.loadGoogleMaps.bind(this), 2000);
}
} NOTE: I am using google-maps package |
@thebiltheory did you manage to solve the problem? i have the same settings as you |
thanks bro
yes I solved
…On Tue, Jul 19, 2022 at 12:09 AM Vitor Costa ***@***.***> wrote:
@thebiltheory <https://github.com/thebiltheory> did you manage to solve
the problem? i have the same settings as you
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AW6UMDD56SHBXLY35IUSFBTVUW2XBANCNFSM4U537DOQ>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Thanks,so much!
Marc
…On Mon, Mar 14, 2022 at 3:10 AM Marc Schipperheyn ***@***.***> wrote:
One thing to be aware of that even with useLoadScript, you have to make
sure that both urls are identical, i.e. contain the same parameters in the
same order. I recommend loading the script in a separate component
const MyPlacesComponentImpl = ({ googleMapsScriptBaseUrl }) => {
const {
placesService,
placePredictions,
getPlacePredictions,
isPlacePredictionsLoading,
} = usePlacesService({
googleMapsScriptBaseUrl,
});
[...]
}
const libraries = ['places'];
const MyPlacesComponent = ({ googleMapsApiKey, language }) => {
const { isLoaded, loadError, url } = useLoadScript({
googleMapsApiKey,
id: 'google-map',
libraries,
language,
});
if (!isLoaded) {
return <Loading />;
}
if (loadError) {
return <LoadingError />;
}
return (
<MyPlacesComponentImpl googleMapsScriptBaseUrl={url} />
);
}
export default MyPlacesComponent;
—
Reply to this email directly, view it on GitHub
<#89 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AW6UMDC47B42IVEDTDOYHGDU7ZRUFANCNFSM4U537DOQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you commented.Message ID:
***@***.***>
|
I had the same problem, to solve it replace 'useJsApiLoader' by 'useLoadScript' both are from the @react-google-maps/api library.
|
I had the same problem because of using useLoadScript with and without places in two different components. In one component, places were not required but in the other I needed 'places'. I made the call to useLoadScript by including 'places' in both components and that removed this problem.
|
I have the same problem but: |
Please use in both components. It should resolve your problem |
Thanks, it can fix my multiple Api calls but unfortunately there is a new error "ReferenceError: google is not defined" since I use GoogleMap too. Do you have an idea of how could it be fixed? |
it working for me |
Has anyone experienced this across two separate components? In one I use autocomplete, in another I use maps. In the autocomplete example, I follow the example material ui provides. In the maps example, I follow the example react google maps provides. Has anyone come up with a solution to load the Google Maps API once for these two different usecases? Thanks in advance! |
Hi, I see that there are many examples but I keep getting the same problem. When I load the google-places-autocomplete component I keep getting the problem that: You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors. And when both things get blocked, the Google map stops searching for places. Here I leave the code to know if I am doing something wrong or if someone found the solution and can help me.
|
"use client";
import { LoadScript, Libraries } from "@react-google-maps/api";
import React, { useState, useEffect } from "react";
const GOOGLE_LIBRARIES: Libraries = ["places", "marker"];
const LoadGoogleProvider = ({ children }: { children: React.ReactNode }) => {
const [isLoaded, setIsLoaded] = useState(false);
const [error, setError] = useState<string | null>(null);
useEffect(() => {
if (!process.env.NEXT_PUBLIC_GOOGLE_API_KEY) {
setError("Google Maps API key is missing.");
}
}, []);
const onLoad = () => setIsLoaded(true);
const onError = () => setError("Failed to load Google Maps");
return process.env.NEXT_PUBLIC_GOOGLE_API_KEY ? (
<LoadScript
googleMapsApiKey={process.env.NEXT_PUBLIC_GOOGLE_API_KEY}
libraries={GOOGLE_LIBRARIES}
onLoad={onLoad}
onError={onError}
>
{isLoaded ? children : <p>Loading Google Maps...</p>}
{error && <p>{error}</p>}
</LoadScript>
) : (
<p>{error}</p>
);
};
export default LoadGoogleProvider; this worked for me, make sure to wrap with layout where your using google components |
Thanks, @ErrorPro! This worked for me. I'm using Update: |
Hi, thanks for your component, it is great.
I have a leaflet map with
react-leaflet-google-layer
and it is using google API too.Got a problem with this
You have included the Google Maps JavaScript API multiple times on this page. This may cause unexpected errors
.I tried to add/remove <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key="> to different parts of the index.html, does not help.
"react-google-autocomplete": "^1.2.6",
Is there any way to fix this?
Thanks.
The text was updated successfully, but these errors were encountered: