import { View, StyleSheet, Linking } from "react-native"; import { Image, Text } from "@tarojs/components"; import './map.scss' import { useEffect, useRef, useState } from "react"; import Taro from "@tarojs/taro"; import { LeafletView } from 'react-native-leaflet-maps'; import { useNavigation } from "@react-navigation/native"; import { TimeFormatter } from "@/utils/time_format"; import { systemLocation } from "@/services/common"; import { useTranslation } from "react-i18next"; import showAlert from "@/components/basic/Alert"; import { kIsAndroid, kIsIOS } from "@/utils/tools"; // let LeafletView = require('react-native-leaflet-maps').LeafletView let location: any = null export default function map() { // const [location, setLocation] = useState(null) const navigation = useNavigation() const [current, setCurrent] = useState(null) const { t } = useTranslation() const [show, setShow] = useState(false) const [count, setCount] = useState(0) useEffect(() => { navigation.setOptions({ headerTitle: 'Choose Location', headerRight: () => { return Done } }); getCurrent() }, []) function confirmChoose() { var today = new Date() var yesterday = new Date(today.getTime() - 24 * 3600 * 1000) var tomorrow = new Date(today.getTime() + 24 * 3600 * 1000) var strYesterday = `${yesterday.getFullYear()}-${TimeFormatter.padZero(yesterday.getMonth() + 1)}-${TimeFormatter.padZero(yesterday.getDate())}` var strTomorrow = `${tomorrow.getFullYear()}-${TimeFormatter.padZero(tomorrow.getMonth() + 1)}-${TimeFormatter.padZero(tomorrow.getDate())}` systemLocation({ lat: (location as any).lat, lng: (location as any).lng, date_start: strYesterday, date_end: strTomorrow, coordinate_system_standard: process.env.TARO_ENV == 'weapp' ? 'GCJ-02' : 'WGS-84' }).then(data => { global.locationDetail = data Taro.setStorage({ key: 'gps', data: JSON.stringify(data as any) }) if (global.swiperDayNightRefresh) { global.swiperDayNightRefresh() } if (global.updateSwiper) { global.updateSwiper() } global.refreshNight() global.refreshDay() navigation.goBack() }) } function getCurrent() { Taro.getLocation({ success(res) { // showAlert({ // title: 'location', // content: JSON.stringify(res) // }) setShow(true) setCurrent(res) location = { lat: (res as any).latitude, lng: (res as any).longitude } }, fail(res) { console.log('location update failed reason', res) if (res.errMsg == 'Permissions denied!') { showAlert({ title: t('feature.auth_sys.location_title'), content: kIsIOS ? t('feature.auth_sys.location_desc') : t('feature.auth_sys.location_android_service_desc'), showCancel: true, cancelText: t('feature.auth_sys.location_cancel'), confirmText: kIsIOS ? t('feature.auth_sys.location_confirm') : t('feature.auth_sys.service_confirm'), confirm: () => { if (kIsIOS) { Linking.openURL('app-settings:') } else { // Linking.openSettings() var Jto = require('react-native').NativeModules.NativeBridge; Jto.openNotificationSettings() } } }) } else { if (kIsAndroid) { var Jto = require('react-native').NativeModules.NativeBridge; Jto.getLocation().then(result => { var res = JSON.parse(result) setCurrent(res) location = { lat: (res as any).latitude, lng: (res as any).longitude } }) } } } }) } function showCurrent() { getCurrent() } function centerPosition() { if (current) { return { lat: current.latitude, lng: current.longitude } } return null } function mapMarkers() { const icon = '' if (current) { return [{ id: 9527, position: { lat: current.latitude, lng: current.longitude }, icon: `
`, // icon: // require('@/assets/images/current_location.png'), // icon: this.state.user_last_car, size: [32, 32], }] } return [] } return { if (e.payload && e.payload.mapCenterPosition) console.log((e as any).payload.mapCenterPosition) // console.log(e) // setCount(count => count + 1) if (e.payload && e.payload.mapCenterPosition) location = e.payload.mapCenterPosition // if (e.event && e.event == 'onMoveEnd') { // if (e.payload && e.payload.mapCenterPosition) // setLocation(e.payload.mapCenterPosition) // } // setTimeout(() => { // if (e.payload && e.payload.mapCenterPosition) // setLocation(e.payload.mapCenterPosition) // }, 500) // if (e.payload && e.payload.mapCenterPosition) // setLocation(e.payload.mapCenterPosition) }} /> {/* { location && Center位置:lat {(location as any).lat.toFixed(4)} lng {(location as any).lng.toFixed(4)} } */} } const styles = StyleSheet.create({ container: { flex: 1, }, scrollContent: { // 您的滚动内容样式 }, overlayView: { // 覆盖视图样式 position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, alignItems: 'center', justifyContent: 'center' }, center: { width: 40, height: 40, marginBottom: 25 }, location_btn: { position: 'absolute', left: 40, bottom: 80, width: 40, height: 40 }, footer: { position: 'absolute', left: 50, right: 50, bottom: 30, backgroundColor: '#fff', alignItems: 'center', justifyContent: 'center', height: 30 } });