Comments (4)
To be able to do this, I had to do a little digging and that is the solution I find online.
For instance, you want to pass your current location dynamically as the country. Google has the Geolocation API that can be called and used to get current location. To do this, since you're already using the Google API I'm sure you already have the Keys setup. Go and enable the Google Geolocation API as part of your project as well.
Then you need to hit the Geolocation API Url, you'll find that in the Docs. This is the link here.
When you read the Docs, you can choose not to pass anything as by default IP is passed to the request body. This returns a response from where you can fetch the latitude and longitude of your current location. Well that is the first step.
Next, you need to enable Google GeoCoding as part of your APIs from Google as well. With this you can now pass your lat and lng to Google Geocode to return a response. This is known as reverse geocoding by Google. Again this is the link to the docs here .
The response object is a lot so I formatted mine to return as little data as possible (Thinking of pricing here). This is my sample url link : https://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&key=YOUR_API_KEY&result_type=country
Added the result type to country as that is what I want. Now after getting this, I can save the value of the country code to a variable and then pass this to the options object, before it is passed to the Input field to restrict the places to your country dynamically.
I hope this helps. You can ask this as a Stack Overflow Question and I provide the answer. I believe it will help a lot.
from ngx-google-places-autocomplete.
I think what he is asking is, how can one "change" the country restriction... this seemingly is only applied once on INIT.
Google's JS API does support changing this via public API, but no support is enabled on this component for that kind of behavior.
from ngx-google-places-autocomplete.
Expecting what @sscholle said. We are not able to put multiple countries under componentRestriction because country
type is string only where in google api it is string | Array<string>
. When this can be fixed?
from ngx-google-places-autocomplete.
Maybe this one can help you
angular-magic/ngx-gp-autocomplete#2 (comment)
from ngx-google-places-autocomplete.
Related Issues (20)
- Debounce time during type a text
- How can I set the HTML5 'autocomplete' value to something different to 'off'
- Testing Error With Angular 12
- Is project is still active ? what about angular 13 support HOT 1
- more than 1 input in the same component
- ERROR ReferenceError: google is not defined HOT 2
- Initialize with code instead of tag
- No directive found with exportAs 'ngx-places'.
- "google is not defined" in Angular 13 HOT 1
- Cannot Restrict Countries HOT 3
- There is no support for Angular 16! HOT 7
- Safari - iOS: When selecting the autocomplete address, it is not selected
- Not compatible with Angular 16 HOT 1
- When this library trigger google services?
- google map Key move from index.html HOT 1
- Dropdown Not Showing HOT 5
- Options Error - All fields required HOT 2
- Issues Returning Certain Addresses HOT 1
- Warning: CommonJS or AMD dependencies can cause optimization bailouts HOT 2
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 ngx-google-places-autocomplete.