|
|
@@ -18,6 +18,7 @@ import MapUILumi from './MapUILumi';
|
|
|
import storage from '../../utils/storage';
|
|
|
|
|
|
const KEY_STORE_LIST = "map_stop_list"
|
|
|
+const KEY_STORE_GPS = "map_location_gps"
|
|
|
|
|
|
export default class HomePage extends Component {
|
|
|
constructor(props) {
|
|
|
@@ -29,6 +30,7 @@ export default class HomePage extends Component {
|
|
|
latitudeDelta: 0.0922,
|
|
|
longitudeDelta: 0.0421
|
|
|
},
|
|
|
+ lastRegion: {},
|
|
|
mapReady: false,
|
|
|
showStation: false,
|
|
|
stationId: "",
|
|
|
@@ -120,7 +122,7 @@ export default class HomePage extends Component {
|
|
|
init() {
|
|
|
if (this.state.stopList.length == 0 && !this.refresh) {
|
|
|
storage.getStorage(KEY_STORE_LIST).then(data => {
|
|
|
- console.log("获取站点缓存", "成功");
|
|
|
+ //console.log("获取站点缓存", "成功");
|
|
|
if (data) {
|
|
|
const list = JSON.parse(data);
|
|
|
this.setState({
|
|
|
@@ -135,6 +137,16 @@ export default class HomePage extends Component {
|
|
|
console.log("获取站点缓存-err", err);
|
|
|
this.checkPermission2Geo(true);
|
|
|
})
|
|
|
+ storage.getStorage(KEY_STORE_GPS).then(data => {
|
|
|
+ //console.log("获取GPS缓存", data);
|
|
|
+ if (data && data.latitude) {
|
|
|
+ this.setState({
|
|
|
+ lastRegion: data
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }).catch(err => {
|
|
|
+ console.log("获取GPS缓存-err", err);
|
|
|
+ })
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -239,7 +251,12 @@ export default class HomePage extends Component {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- checkPermission2Geo(refresh) {
|
|
|
+ checkPermission2Geo(refresh, button) {
|
|
|
+ if (button && this.state.lastRegion.latitude) {
|
|
|
+ this.setState({
|
|
|
+ region: {...this.state.lastRegion}
|
|
|
+ });
|
|
|
+ }
|
|
|
if (this.refresh == refresh) {
|
|
|
return;
|
|
|
}
|
|
|
@@ -299,6 +316,7 @@ export default class HomePage extends Component {
|
|
|
latitudeDelta: 0.0922,
|
|
|
longitudeDelta: 0.0421
|
|
|
}
|
|
|
+ this.saveGPSCache(region);
|
|
|
//console.log("getGeoLocation", region);
|
|
|
//if (this.state.stopList.length == 0) { //只加载一次
|
|
|
let time = new Date().getTime();
|
|
|
@@ -501,6 +519,13 @@ export default class HomePage extends Component {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
+ saveGPSCache(location) {
|
|
|
+ storage.setStorageJson(KEY_STORE_GPS, location);
|
|
|
+ this.setState({
|
|
|
+ lastRegion: location
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
render() {
|
|
|
return (
|
|
|
<View style={ui.flex1}>
|
|
|
@@ -512,7 +537,7 @@ export default class HomePage extends Component {
|
|
|
onMapReady={() => this.onMapReady()}
|
|
|
onFavorite={() => this.favoriteSite()}
|
|
|
onCloseInfo={() => this.onCloseInfo()}
|
|
|
- onLocation={() => this.checkPermission2Geo(true)}
|
|
|
+ onLocation={() => this.checkPermission2Geo(true, true)}
|
|
|
useApplesMap={this.settingInfo.useApplesMap}
|
|
|
showUserLocation={this.state.hasPermission && this.settingInfo.alwaysLocation}
|
|
|
viewChargeStation={id => this.viewChargeStation(id)}/>
|
|
|
@@ -523,7 +548,7 @@ export default class HomePage extends Component {
|
|
|
onMapReady={() => this.onMapReady()}
|
|
|
onFavorite={() => this.favoriteSite()}
|
|
|
onCloseInfo={() => this.onCloseInfo()}
|
|
|
- onLocation={() => this.checkPermission2Geo(true)}
|
|
|
+ onLocation={() => this.checkPermission2Geo(true, true)}
|
|
|
useApplesMap={this.settingInfo.useApplesMap}
|
|
|
showUserLocation={this.state.hasPermission && this.settingInfo.alwaysLocation}
|
|
|
viewChargeStation={id => this.viewChargeStation(id)}
|