大佬教程收集整理的这篇文章主要介绍了Typescript React Native Maps Polyline 跟踪路线(如 uber),大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试实现一个跟踪路由器应用程序,所以当用户走路时,应用程序会注册它的路径。
我做到了,但有时会奏效,有时却很糟糕。
我需要知道我是否可以优化我的代码,这样被跟踪的路线会流动得更好。
我猜它是 useEffect 将路由存储在我调用的数组中,这会导致应用程序运行缓慢,但我不知道如何在没有 useEffect 的情况下跟踪它,或者找到一个计时器或一些不会锁定应用程序运行的东西不时获取职位。
这是我的代码的一些部分:
位置挂钩:
interface coordenatesProps{
latitude: @R_772_10793@er;
longitude: @R_772_10793@er;
}
const [points,setPoints] = useState<coordenatesProps[]>([]);
//I am storing the route at that point state,working as array incremented by useState
//then,i got that function:
const loadposition = useCallBACk(async () => {
.
.
.
GeoLOCATIOn.getCurrentposition(
async ({ coords }) => {
setCoords({
latitude: coords.latitude,longitude: coords.longitude,});
setPoints((statE) => [...state,coords]);
},() => {
Alert.alert('Não foi possível obter a localização');
},{ enableHighAccuracy: true,timeout: 20000,maximumAge: 1000,showLOCATIOnDialog: true }
);
}
},[]);
useEffect(() => {
loadposition();
},[]);
然后我得到了 polyline 组件,我称之为“路径”:
import {useLOCATIOn} from '../../hooks/LOCATIOn';
const Path: React.FC = () => {
const {points} = useLOCATIOn();
return (
<polyline
coordinates={
points
}
geodesic = {truE}
strokecolor = {'#6F9F77'}
strokeWIDth = {6}
/>
);
}
export default Path;
最后,我设置了地图视图的 mainPain,并在中间设置了我的组件:
<MapVIEw
..props...
>
.
.
.
<Path/>
.
.
.
<MapVIEw/>
我这样做对吗?你们知道更好的方法吗?谢谢。
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
以上是大佬教程为你收集整理的Typescript React Native Maps Polyline 跟踪路线(如 uber)全部内容,希望文章能够帮你解决Typescript React Native Maps Polyline 跟踪路线(如 uber)所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。