-
Notifications
You must be signed in to change notification settings - Fork 821
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
How to Support "Google Place Autocomplete" (with example) #431
Comments
Thats cool but whats more interesting is connecting the search bar with SebM Maps.
The reason why you have to click in the map is because it is a separate component. I am working on a solution with Sebastians Map API, Google Key, Search Bar with Places from the 'getNativeMap()'. I need some time and await NPM Release 0.12.0 Stay tuned for a solution. |
I personally have the problem when I do that I get the error the map was not found. |
Ok guys, I'll close this as this is not an issue report or a feature request. Feel free to comment below though. |
@cesargalindo shared a solution for the "map is not updating without a click" issue I had I've updated the plunker accordingly |
@Pitouli hello, thanks for your solution, i have used it and found a better way to support Autocomplete, because when using your solution i had multiple google api warning and my map crashed when using SebmGoogleMap directive. Here is the solution: In my main.ts
And in my app.component.ts
You now can get rid of: It also worked with :
so i think it works with all the google maps object classes. Hope it helps. 😃 |
@fernando-gl right. My code is almost 1:1 |
Do you call autocomplete after ngAfterContentInit ? |
@brian-singer I am calling it from ngOnInit but i just tried on ngAfterContentInit and its working good also. |
I am trying to get this work like you suggested @fernando-gl but I can't get it to work, can you share a plunker or something, I am using angular 2 final, I am not sure this will change anything or not |
@daBishMan Yes, It's changing. Angular 2.0.0 removed bootstrap function. @SebastianM Looks like it's a really good time to create some new Plunkers for different, different examples. |
Instad of using bootstrap in main.ts, Just use
in your app.module.ts. |
Hello @daBishMan , as @andriesvn01 said, you just have to change your import from main.ts to app.module.ts like this:
You can see the updated "getting started" here: |
@fernando-gl I use your above code for my app.module.ts The map displays, but I get the Console error: You have included the Google Maps API multiple times ... It seems to load 4 times. Do you have any thoughts about the source of the problem, and how to fix it? |
@mLaird Hello, have you tried removing the library from your index.html? |
@fernando-gl I removed the Google Map link in index.html and the multiple load problem went away. Thanks very much. You guys have built a slick map app. |
Hi @fernando-gl , I'm using your solution, but I can't load the Places library. I'm currently on Angular 4+ and agm/core 1.0.0-beta.0. I'm importing the module as this:
The error I get is: What might be causing this issue? |
late but.. "AutocompleteService" not "Autocomplete" |
Hello @viktorstaikov , sorry for being late, have you managed to get it working already? I haven't used this for a while, so I don't know If something has changed, If you want i can try to get it working again. |
Yeah, after some tinkering and installing deps I've got it working. It wasn't something with the solution itself. |
@viktorstaikov Great to hear that!, good luck coding! |
Having spent tens of hours to find how to support "Autocomplete", I share with you my solution (which is technically completely independent from the angular2-google-maps API at the moment, since I did not succeeded in reusing the LazyMapLoading 😛 ).
Here is a plunker which shows how to:
http://plnkr.co/edit/NtfCPol50mlwGoiB8UZu
What I've done:
1/ I'm loading the Google Maps API (with the "places" library) directly in the
index.html (line 28)
, so I have to use the "no lazy load" functionality in themain.ts (line 135)
. Note that in my personal implementation, I am not using "Bootstrap", but I declare the providers in the@Component
2/ I make a reference to the Google Map API (
main.ts line 19
)3/ I connect the Autocomplete in the ngOnInit (
main.ts lines 63 to 73
)Tip :
main.ts line 63
I have a reference to the input field. Here, I simply used a "getElementByID()
". In my real project, I needed to use a "querySelector()
"... I precise in case you have issues selectionning the input filed...IMPROVEMENT (if someone know how to) :
How could we use the "Lazy Loader"? I do not know how to access the google reference after lazy loading.
BUG?
Why when the location changed and that I change the latitude and longitude it's only taken into account if I click the map? You could put an alert (or simply read the console) and you will see that the modification of the values is not made after the click.
=> I've updated the plunkr thanks to a solution provided by @cesargalindo
https://gitter.im/SebastianM/angular2-google-maps?at=576197ff36c83a880205fd64
PS: yeah, it's that easy. But it's my first Angular project, and I'm learning directly by doing. So simple tasks become quite difficult! 😆
The text was updated successfully, but these errors were encountered: