use-position icon indicating copy to clipboard operation
use-position copied to clipboard

[Violation] Only request geolocation information in response to a user gesture

Open gkrinc opened this issue 5 years ago • 3 comments

I'm seeing an this Violation increasing continuously on the page [Violation] Only request geolocation information in response to a user gesture.

Screen Shot 2020-01-20 at 2 02 43 PM

This is my usage of usePosition

const {
    latitude: userLatitude,
    longitude: userLongitude,
    error: geoLocationError,
  } = usePosition(true, {
    enableHighAccuracy: CONSTANTS.locationServices.enableHighAccuracy, // true
    timeout: CONSTANTS.locationServices.timeout, // 60000
  });

This seems to only be happening in Chrome. Safari and Firefox aren't reporting the same violation. I did notice in Firefox though that if I didn't check the box to remember me allowing location services the box repeatedly popped up to ask me to allow. Is this related?

gkrinc avatar Jan 20 '20 19:01 gkrinc

Hi @gkrinc , I keep getting this error: `Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

  1. You might have mismatching versions of React and the renderer (such as React DOM)
  2. You might be breaking the Rules of Hooks
  3. You might have more than one copy of React in the same app See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.`

I'm doing a similar usage of usePosition, so I don't think I'm breaking any hooks rules (but I might be)? Did you run into this issue at all/know of a fix? thanks :)

michaeldu1 avatar May 11 '20 21:05 michaeldu1

The issue is that the browser requires SSL for this to work, here is one quick solution:

HTTPS

A really simple solution is mkcert

  1. brew install mkcert
  2. mkcert -install
  3. mkcert localhost -> The certificate is at "./localhost.pem" and the key at "./localhost-key.pem" ✅
  • QuickStart: (yarn | npm run) start:https
  • Custom SSL Cert: HTTPS=true SSL_CRT_FILE=./localhost.pem SSL_KEY_FILE=./localhost-key.pem npm start

This will setup and install a SSL certificate, and allow you to run GeoLocation.

Wkasel avatar Jul 21 '20 09:07 Wkasel

Eu estava encontrando o mesmo problema utilizando o chrome. Tentei também no safari e deu o mesmo erro. Sem esperança, tentei no edge, e num é que apesar da marcação dos erros, eu consegui debugar...? Ainda não encontrei o motivo causal de porque o Chrome e safari bugaram...

Fabio-TI avatar Mar 14 '22 18:03 Fabio-TI