鍍金池/ 問答/網(wǎng)絡(luò)營銷  HTML/ 用百度地圖API進行逆地址解析,獲得的數(shù)據(jù)改怎么存下來,操作報錯

用百度地圖API進行逆地址解析,獲得的數(shù)據(jù)改怎么存下來,操作報錯

// 在geoc.getLocation(point, function (rs) {里,怎么把返回的數(shù)據(jù)存下來呢,我通過方法或是setState保存我需要的數(shù)據(jù),都報錯哎
//在這個方法里是不是外部的數(shù)據(jù)都不能進去
// 單獨寫一個html的demo是沒問題,在react上不好使。

var ggPoint = new BMap.Point(116.40387397,39.91488908);//測試地址
//坐標(biāo)轉(zhuǎn)換完之后的回調(diào)函數(shù)
var translateCallback = function (data) {
    const geoc = new BMap.Geocoder();
    var point = new BMap.Point(data.points[0].lng, data.points[0].lat);
    geoc.getLocation(point, function (rs) {
        console.log(rs.address);
        // this.props.biubibiu(rs);//redux的action
        // this.rsaddress(translateCallback); //Uncaught TypeError: this.rsaddress is not a function
        // this.setState({...//也不行
        
    });
}
//gps轉(zhuǎn)百度
var convertor = new BMap.Convertor();
var pointArr = [];
pointArr.push(ggPoint);
convertor.translate(pointArr, 1, 5, translateCallback);
回答
編輯回答
莓森

如果state被刷新了,那你可以放到sessionStorage中,需要的時候,再取出來。

2018年7月12日 19:24