0

在我的场景中,我想获取用户的当前位置并在该当前位置的地图上显示一个图钉。我试过了,但我面临以下问题:

TypeError:未定义不是对象(评估'navigator.geolocation.getCurrentPosition')

我该如何解决上述问题?

4

1 回答 1

0

您还可以使用 RNLocation 包来获取我已与您共享代码的用户位置。您只需要安装该软件包。

  const [location, setLocation] = useState(null);

useEffect(()=> {
    RNLocation.configure({
        distanceFilter: 5.0
    })

    RNLocation.requestPermission({
        ios: "whenInUse",
        android: {
            detail: "coarse"
        }
    }).then(granted => {
        if (granted) {
            RNLocation.subscribeToLocationUpdates(locations => {
                setLocation(locations)
            })
        }
    })
},[])
于 2021-01-25T06:37:15.213 回答