0
ジオロケーション変数position.coords.lat/long
を表示しようとしていますが、グローバルスコープに値を格納する際に問題があります。原子炉でジオロケーションを使用する
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