bazrafkan / google_place

A new Flutter package for handle google place api
MIT License
84 stars 122 forks source link

Web proxyUrl #35

Closed mmhobi7 closed 2 years ago

mmhobi7 commented 2 years ago

I am having trouble with proxyUrl, even with the demo of proxyUrl: 'cors-anywhere.herokuapp.com') or cors.bridged.cc (from https://github.com/Rob--W/cors-anywhere/issues/301#issuecomment-870990778). Any help would be appreciated.

LucaDillenburg commented 2 years ago

As described by this issue the cors-anywhere.herokuapp.com proxy is being limited and basically should not be used as a long term solution. You can use it by going to cors-anywhere.herokuapp.com in the browser and clicking in "Request temporary access to demo server". However, this will only solve the problem for a couple of minutes. After that, you would need to click again. A free long term solution (still not production ready) would be to create your own heroku app with using the cors-anywhere repository. You can do that with the commands bellow:

# setup
git clone https://github.com/Rob--W/cors-anywhere.git
cd cors-anywhere
npm install
heroku create

# deploy
git push heroku master

ps: I didn't come up with the solution but for some reason I cannot find who did.

Also, this should be added to the README docs at the end. I can do that if approved.

log02 commented 2 years ago

Hi @LucaDillenburg. You say (not production ready) What do you think would be a good production solution ? My understanding is that google_place should implement web call with Google Maps JavaScript API V3.

jardon-u commented 2 years ago

For those discovering the issue. Google place api does not accept other websites to serve google content. Seems that this is only possible if you use the "Google Maps JavaScript API V3" (the official api that is web only). Unfortunately google_place (the flutter package) does not support this. The solution for now is to deploy your own CORS proxy that will request the google place API and modify the response header to allow displaying the content anywhere.There are public CORS proxies but they limit the traffic and can be unsafe. If you are on Heroku, check @LucaDillenburg answer in this thread. If you are on GCP, just follow the instructions in https://github.com/taichunmin/gcf-cors-anywhere Finally, depending on your CORS proxy api (if you use the GCP link above for example) you might need to use a patched version of google_place (the master branch does not allow some formats: egs my-proxy/cors?url=...). In this case add google_place like this to your puspec.yaml

 google_place:
    git:
      url: https://github.com/Desync-o-tron/google_place
      ref: feature-paths-in-proxyUrl
LucaDillenburg commented 2 years ago

@log02 I believe a better solution would be to use the native SDKs instead of http requests in flutter web. I haven't tested it yet, but I believe it would remove the need of a cors-anywhere server. I found a package that claims to do just that: flutter_google_places_sdk. However, if you intent to use this package, you could pay for either GCP or Heroku, as the free versions of these services probably don't provide enough enough instances, RAM and etc for production use.

log02 commented 2 years ago

thanks @LucaDillenburg I will test flutter_google_places_sdk