如果用户允许,我想使用地理位置在屏幕上显示内容,
它工作正常,但突然不再工作
在 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);