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