GithubHelp home page GithubHelp logo

Comments (4)

Juxlarry avatar Juxlarry commented on June 2, 2024 1

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.

sscholle avatar sscholle commented on June 2, 2024 1

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.

coding-noddy avatar coding-noddy commented on June 2, 2024 1

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.

dancornilov avatar dancornilov commented on June 2, 2024 1

Maybe this one can help you
angular-magic/ngx-gp-autocomplete#2 (comment)

from ngx-google-places-autocomplete.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.