timwangdev / react-native-geocoder-reborn

:round_pushpin: Geocoding services for react-native
MIT License
135 stars 38 forks source link

iOS google version should be using native library instead of 'webclient' #20

Open lzbikowski-opensource opened 4 years ago

lzbikowski-opensource commented 4 years ago

First of all, thank you for the time you have put to 'resurrect' geocoder lib,

Saying that - I have noticed that it's using google web API instead of native iOS.

As a result, it's not possible to limit API key usage (and it can be stolen). Do you have any plans to move to native ios API?

timwangdev commented 4 years ago

Hi @lzbikowski-opensource , it is using native API by default. "Force Google on iOS" options is for someone who needs consistent results across platforms.

lzbikowski-opensource commented 4 years ago

Hi @timwangdev thanks for a quick reply. that is what I meant - The force-google on iOS is using webapi.

As an example - if you generate Google API credentials for 'ios' the request will be rejected (I assume that through iOS sdk would be accepted as the bundle id is sent). If you use 'webapi' key it works.

Does it make any sense ? :-)

The annoying part about 'native iOS' (not google) is lack of support for simultaneous requests... I am exploring my options and considering to write a piece of native code/PR, but will try unimodules first...

timwangdev commented 4 years ago

@lzbikowski-opensource I got your idea.

Using native API requires embedding or depending on Google Maps SDK, which may be not the direction I'm looking for. Since the package only using a geocoder service. And also, native SDK seems only providing reverse geocoding.

API keys restrictions could be an issue here, I will leave this open for discussion. Do you have any idea about this?

lzbikowski-opensource commented 4 years ago

Let me explore a bit and come back to discuss further

lzbikowski-opensource commented 4 years ago

@timwangdev for reference:

It's indeed missing feature of SDK: https://issuetracker.google.com/issues/35822639 However seems possible as per comment within this ticket (not tested): "We can call the API directly in the app without using the SDK. However, there is no document to tell where to put the bundle ID. In fact, you have to put bundle ID in the HTTP request headers with key = X-Ios-Bundle-Identifier*."

"The important bit is to populate the X-Ios-Bundle-Identifier header.""

As per https://github.com/GoogleCloudPlatform/cloud-vision/issues/16

Swift:

request.addValue(NSBundle.mainBundle().bundleIdentifier ?? "", forHTTPHeaderField: "X-Ios-Bundle-Identifier") Objective-C:

[request addValue:[[NSBundle mainBundle] bundleIdentifier] forHTTPHeaderField:@"X-Ios-Bundle-Identifier"];

I will be exploring further and share any results here to help others.

timwangdev commented 4 years ago

According to FaridSafi/react-native-google-places-autocomplete#140 , and FaridSafi/react-native-google-places-autocomplete#526 , it seems that adding the Referer header will do the work.

Alb93 commented 4 years ago

Hi @timwangdev, how you can use Referer prop to get the Api Key not used outside your app? Can you post an example? Thank you

bell-steven commented 4 years ago

Hi @timwangdev, i'm the maintainer of react-native-google-places-autocomplete.
Just a heads up, adding a referrer header doesn't seem to work (we probably will have to roll back that PR). Using HTTP referrers can only be used with the JS SDK, otherwise you will receive this error: API keys with referer restrictions can not be used with this API. If something changes i'll try and update here.

timwangdev commented 4 years ago

Hi @bell-steven, thank you very much for updating me about this. That actually makes a lot of senes.

I'll update the project about this limitation.