首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ReferenceError:找不到变量: dis

ReferenceError:找不到变量: dis
EN

Stack Overflow用户
提问于 2020-12-24 12:58:15
回答 1查看 248关注 0票数 0

ReferenceError:找不到变量: dis

你能帮我使用dis吗?我需要在dis中使用targetControl()

没有做以上所有的事情。您能在这个链接上看到完整的代码吗?

link=> https://ctxt.io/2/AACg5g6UFQ

代码语言:javascript
复制
export default class Mapview extends React.Component {
    constructor(props) {
        super(props);

        this.state = {
              latitude: 0,
              longitude: 0,
              error: null,
              coords: [],
              places: null,
              selectedLat: "",
              selectedLang: "",
              distance: "",
              mesafeFarki: 1,
        };
    }
    
    showCoords() {
        const arrayMarkers = [];
        var coordsLatLang = [];
        var allCoords = [];
        var selectedCoordLat = [];
        var selectedCoordLang = [];
        var dis = [];
    
        Geolocation.getCurrentPosition(position => {
          var userLat = position.coords.latitude
          var userLang = position.coords.longitude
    
          for (let index = 0; index < this.props.locCoord.length; index++) {
            coordsLatLang = this.props.locCoord[index].split(',')
            allCoords.push(this.props.locCoord[index].split(','))
            selectedCoordLat.push(allCoords[index][0])
            selectedCoordLang.push(allCoords[index][1])

            dis.push(getDistance(
              { latitude: userLat, longitude: userLang },
              { latitude: selectedCoordLat[index], longitude: selectedCoordLang[index] }
            ))
        .
        .
        .
        .
        
        .
          hedefiKontrol(){
            this.setState({ 
              
            mesafeFarki : ((dis[index] / 1000).toFixed(2)),// RefereanceError:Can't find variabal:dis 
            
                });
                if (mesafeFarki < 0.2) {
                      this.props.navigation.navigate("SSS");
                  }
          }
}
EN

Stack Overflow用户

发布于 2020-12-24 13:05:22

尝试在Gelocation函数中声明var dis = [] .

代码语言:javascript
复制
 Geolocation.getCurrentPosition(position => {
      var userLat = position.coords.latitude
      var userLang = position.coords.longitude
      var dis = []
      
      ...
      
     }

如果不起作用,将其放入构造函数方法中。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/65438637

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档