ReferenceError:找不到变量: dis
你能帮我使用dis吗?我需要在dis中使用targetControl()。
没有做以上所有的事情。您能在这个链接上看到完整的代码吗?
link=> https://ctxt.io/2/AACg5g6UFQ
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");
}
}
}发布于 2020-12-24 13:05:22
尝试在Gelocation函数中声明var dis = [] .
Geolocation.getCurrentPosition(position => {
var userLat = position.coords.latitude
var userLang = position.coords.longitude
var dis = []
...
}
如果不起作用,将其放入构造函数方法中。
https://stackoverflow.com/questions/65438637
复制相似问题