0
Geolocation 변수 position.coords.lat/long
을 표시하려고하는데 전역 값에 값을 저장하는 데 문제가 있습니다.탐색기에서 리액터로 Geolocation 사용
var GeoLoco = React.createClass({
lat: 0,
long: 0,
handler: function(position) {
this.lat = position.coords.latitude;
this.long = position.coords.longitude;
console.log("Lat,Long: "+this.lat+","+this.long);
},
render: function() {
navigator.geolocation.getCurrentPosition(this.handler);
return <p>Lat,Long: {this.lat},{this.long}</p>;
}
});
console.log
표시 위치 데이터 만 this.lat
및 this.long
당신의 변수의 값이 변경 되더라도 0
타이밍 문제 였음을 알았습니다. 너무 많이'this.forceUpdate()'가 트릭을 해 주셔서 감사합니다. –
이 문제를 해결 된 것으로 표시하십시오. :) – Robiseb