地理位置在 Chrome 浏览器上不起作用

时间:2021-01-22 00:58:10

标签: javascript reactjs geolocation

如果用户允许,我想使用地理位置在屏幕上显示内容,

它工作正常,但突然不再工作

在 Firefox 中运行良好

在谷歌地图中也不起作用,所以我认为这不是因为网站不安全

我正在使用 GeoLocated

这是代码

const AddUserPage = ({ coords, isGeolocationEnabled }) => {
  const [location, setLocation] = useState(null)
  useEffect(() => {
    if (coords) {
      setLocation({ lat: coords.latitude, lng: coords.longitude })
    }

  }, [coords])

  const changeLocation = (location) => {
   setLocation(location)
  }

  if (!isGeolocationEnabled) {
    return <div>fuck you</div>
  }
  if (coords) {
    return (
      <div style={{ width: '300px', height: "300pc" }}>
        <UserMap changeLocation={changeLocation} lat={coords.latitude} lng={coords.longitude}></UserMap>
        <Button onClick={()=>{
          console.log(location)
        }}>current location</Button>
      </div>
    );
  }
  return <div>nslknl;ij'poj</div>
};

export default geolocated({
  enableHighAccuracy: true,
  timeout: 5000,
  maximumAge: 0
})(AddUserPage);

0 个答案:

没有答案
相关问题