| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- /* eslint-disable react/style-prop-object */
- import * as WebBrowser from "expo-web-browser";
- import * as React from "react";
- import { WebView } from "react-native-webview";
- import { useMount } from "ahooks";
- import { useModel } from "flooks";
- import { getLocation } from "../Utils/MapUtils";
- export default function SearchMapScreen({ navigation }) {
- const { saveLocation } = useModel("userModel");
- const webRef = React.useRef();
- const { showDialog } = useModel("dialogModel", true);
- useMount(() => {
- getLocation().then(res => {
- let location = "";
- // saveLocation(
- // "江苏省南京市建邺区白龙江东街9号新城科技园科技创新综合体",
- // 31.981402,
- // 118.737781
- // ).then(() => {
- // navigation.goBack();
- // });
- if (res.addressName !== "定位失败") {
- location = `${res.location.lat},${res.location.lng}`;
- }
- webRef.current.injectJavaScript(`window.setLocation('${location}')`);
- Portal.remove(key);
- });
- });
- const [chooseLocal, setchooseLocal] = React.useState({});
- function showChange(val, title, max, type) {
- showDialog({
- pla: "",
- maxLength: max || 50,
- defaultValue: val,
- InputType: type,
- isEdit: true,
- title,
- cancelable: true,
- confirmCallback: info => {
- saveLocation(info, chooseLocal.lat, chooseLocal.lng).then(() => {
- navigation.goBack();
- });
- },
- });
- }
- return (
- <WebView
- ref={webRef}
- source={{
- uri: "http://dingdong.izouma.com/map/chooseLocation",
- }}
- // style={{ flexGrow: 1, width: "100%" }}
- onMessage={({ nativeEvent }) => {
- const info = JSON.parse(nativeEvent.data);
- setchooseLocal({ lat: info.latlng.lat, lng: info.latlng.lng });
- showChange(info.poiaddress + info.poiname, "请录入详细地址", 100);
- }}
- />
- );
- }
|