bramus / react-native-maps-directions

Directions Component for `react-native-maps`
MIT License
1.24k stars 196 forks source link

Api key restricted to android apps with enabled directions api does not work. #158

Open miroslavskela opened 3 years ago

miroslavskela commented 3 years ago

I have api key restricted to android apps, and enabled maps and directions api, and maps are working but directions not with "ReactNativeJS: MapViewDirections Error: Error on GMAPS route request: This IP, site or mobile application is not authorized to use this API key. Request received from IP address xx.xxx.xxx.xxx, with empty referer" error. I tried with key that does not have restrictions and it works. So if someone knows how to get it work but with restrictions it would be great. Thank you.

chramos commented 3 years ago

I'm facing the same issue

I found this in stackoverflow: https://stackoverflow.com/a/56417713

osxsystem commented 3 years ago

Same here!

LeandroTorresSicilia commented 2 years ago

same

enaluz commented 2 years ago

MapViewDirections Error: Error on GMAPS route request: This IP, site or mobile application is not authorized to use this API key. Request received from IP address ****************, with empty referer

I'm getting this warning in metro. I'm using an API key that's restricted to iOS apps with the bundle ids for my project. In light of what @chramos referenced in the SO post, how would you recommend we move forward @bramus?

FadiAboMsalam commented 2 years ago

ANY update on this facing same issue !

Eli-Nathan commented 1 year ago

As @chramos mentioned this is due to the directions API being a web service. You can see a table here of the restriction options for each service.

If you have a restricted API key, it wont work if you hit it from a native app. Google expects you to hit it from a backend server. You'll need to create your own API that your app can call. That API will need to then make the request to Google for directions (You can restrict the API key to only allow your server's IP address) and then pass the response back to your app.

Potentially another gotcha here though, is if your server makes that request, what's stopping someone just hitting your server for map directions and running up your Google Cloud bill that way? You'll probably need to have authentication on your app, that sends a token to your server to make sure it's a legitimate request from your app.

Also worth noting that this library wont work if you do that. As it makes the request to Google and that's not configurable, you'd need to either fork this package and alter it with your API endpoint or you could just grab the component from here and place it in your app with some alterations.