-
Notifications
You must be signed in to change notification settings - Fork 64
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
Google Maps API multiple times error with Angular 2 #67
Comments
Please provide full jsbin that repos the issue. On Fri, Feb 12, 2016, 4:36 PM Roberto Simonetti [email protected]
|
Not sure exactly what's going on here, but you described the underlying problem. The Google Maps API throws these warnings when the API is loaded more than once. I'm not seeing where google-maps-api is used in your code. The google-map element uses google-maps-api to load the JS API code. If it's used again with different parameters, you'll get the console warnings. But you should never really need use you google-maps-api directly. |
In fact, the google-maps-api element is used only once through the google-map. But the request of the JS API is made for each property. So I have no other solution than building a custom element with the properties already set? |
That's correct. Because of how the Maps API loads, it's important to have all your properties known ahead of time, before creating
|
I'm sorry @ebidel , but I don't want to change the params at runtime, I would just like to understand why this simple use of google-map: |
It doesn't: http://jsbin.com/tipemoseka/edit?html,output |
Yes, it does. As I said, the error occurs if it is used with Angular 2. Thanks anyway. |
This is an old post and hopefully you have resolved this. I ran in to an issue that might just be related. Seems like if you import the GOOGLE_MAPS_PROVIDERS in more than one location it gives you this issue. So its better to add it to bootstrap once. The following forum helped me solve my problem: |
Hi @nooruddinabbas, thanks for your interest, but I haven't solved the problem of coexistence between Angular 2 and Polymer google-maps-api, and I decided to create custom components in Angular 2, just like angular2-google-maps library. Greetings |
Yeah, I'm running into this same exact issue when trying to use Angular2 👍 |
And I just have to add, I find it kind of ridiculous that google's polymer components aren't playing nicely with google's angular2. How long has angular2 been in development now?.... |
We were hoping to use the Polymer Google Map in our Angular 2 application as well. But due to this blocking (and closed) issue, we'll have to use https://github.com/SebastianM/angular2-google-maps instead. This issue may need to be re-opened against the Polymer element itself https://github.com/GoogleWebComponents/google-map/issues since this is not really resolved. |
It looks like Angular is doing something interesting under the hood. Does anyone know more about the internals of how component markup is parsed and setup in Angular2? Seems like it strips attributes and re-adds them? I see 3 requests being made to the Maps API loader:
Each time an attribute is being added, but the original code has all three at instance time. Compare this to the jsbin I posted that doesn't use Angular. One call is made with all 3 attributes. cc @robdodson |
I think we understand what's happening now. Angular's bootstrap reconstructs the DOM from the string template. This means the attributes are actually "removed" then added one by one: http://i.imgur.com/4b98YFd.png Hence, the multiple loads of the library, each adding a new parameter. To guard against this, the loading code can probably use a debouncer or be smarter about not making additional calls. Also, it would be worth removing observers for things like clientId/apiKey/version after they've been set the first time. One of the problems here is that we're observing changes to those properties in the first place. After initial load, it doesn't make sense to be able to update those values. Doing so leads to weird errors like this with the Maps API. |
The debouncer and removing observers after they are set both sound like great ideas that would benefit Angular 2 users and others in the future. Thanks for taking another look at this @ebidel! |
Is there any workaround? |
@MrChoclate we are happy with angular2-google-maps (mentioned here #67 (comment)) for now. |
If I recall @ebidel fixed this? |
Not yet :\ Given the info in #67 (comment), it would be awesome if someone wants to propose a PR that would be cool. |
Hi,
I am trying to use google-map element with Angular 2: the display is correct, and all the google-map properties work well, but the properties of google-maps-api. For example:
<google-map api-key="AIzaSyCqrVHpM_zlUEPtxJPQiFYIqwfKcOctB_M" language="en" latitude="37.77493" longitude="-122.41942"></google-map>
I see the following error twice, once for each property that belongs to the google-maps-api (
language
andapi-key
):You have included the Google Maps API multiple times on this page. This may cause unexpected errors.
In fact, in the browser Sources, I see three loads of Google Maps Api: one with no parameters, one with the API key and finally one with the API key and the language.
If I set directly into the google-map the properties, the error does not occur:
<google-maps-api id="api" api-key="AIzaSyCqrVHpM_zlUEPtxJPQiFYIqwfKcOctB_M" client-id="[[clientId]]" version="[[version]]" signed-in="[[signedIn]]" language="en" on-api-load="_mapApiLoaded"></google-maps-api>
I have seen that this error occurs in other cases, such as: #22
Is there an explanation? Thanks.
The text was updated successfully, but these errors were encountered: