Git Product home page Git Product logo

Comments (9)

sibelius avatar sibelius commented on July 28, 2024 2

@stephenmcd are you willing to accept a pull request to make compatible with react-native?

it would make this package https://github.com/FaridSafi/react-native-google-places-autocomplete easier to maintain

from google-maps-services-js.

stephenmcd avatar stephenmcd commented on July 28, 2024

One note on this - using the web services from a mobile device is highly discouraged, as it exposes your unrestricted API key to malicious users.

from google-maps-services-js.

joncursi avatar joncursi commented on July 28, 2024

@stephenmcd Indeed, it is not a perfect solution. I am using react-native-config to manage keys the best I can, but they still get bundled with the app and could get reverse engineered out I suppose.

Is there a better way to call these APIs from a React Native app?

from google-maps-services-js.

stephenmcd avatar stephenmcd commented on July 28, 2024

Best approach is a server-side component that acts as a proxy between devices and third-party APIs such as maps.

from google-maps-services-js.

stephenmcd avatar stephenmcd commented on July 28, 2024

I'll close this for now - we could probably get it working by swapping out https with fetch, but doing so would encourage insecure practices as mentioned above. You can always fork the library and patch it if you'd like to ignore this.

from google-maps-services-js.

stephenmcd avatar stephenmcd commented on July 28, 2024

How would you address the issues I mentioned?

from google-maps-services-js.

sibelius avatar sibelius commented on July 28, 2024

I think it is a good idea to move to fetch instead of https

making it available in react-native could be a good thing for simple demos

from google-maps-services-js.

iBobik avatar iBobik commented on July 28, 2024

Possible workaround is to use this library only for types, but send requests by anything our environment likes.

This is how I use it in Nitro on edge worker:

import { defaultUrl, PlaceAutocompleteRequest, PlaceAutocompleteResponseData } from '@googlemaps/google-maps-services-js/dist/places/autocomplete'

const { googleMapsApiKey } = useRuntimeConfig()

export default defineEventHandler<{ query: {
  input: string
  language: string
  sessionToken: string
} }>(async (event) => {
  const { input, language, sessionToken } = getQuery(event)

  try {
    const data = await $fetch<PlaceAutocompleteResponseData>(defaultUrl, {
      query: {
        input,
        language,
        key: googleMapsApiKey,
        sessiontoken: sessionToken,
      } as PlaceAutocompleteRequest['params']
    })
    if (data.status !== 'OK' && data.status !== 'ZERO_RESULTS')
      throw createError({ statusCode: 400, statusMessage: 'Bad Request' })

    return data
  }
  catch (err) {
    console.log(err)
    throw createError({ statusCode: 500, statusMessage: 'Internal Server Error' })
  }
})

from google-maps-services-js.

iBobik avatar iBobik commented on July 28, 2024

Btw, on all frontends we need to use proper API key - read only access. It does not matter what client library we use.

from google-maps-services-js.

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.