SearchMapScreen.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* eslint-disable react/style-prop-object */
  2. import * as WebBrowser from "expo-web-browser";
  3. import * as React from "react";
  4. import { WebView } from "react-native-webview";
  5. import { useMount } from "ahooks";
  6. import { useModel } from "flooks";
  7. import { getLocation } from "../Utils/MapUtils";
  8. export default function SearchMapScreen({ navigation }) {
  9. const { saveLocation } = useModel("userModel");
  10. const webRef = React.useRef();
  11. const { showDialog } = useModel("dialogModel", true);
  12. useMount(() => {
  13. getLocation().then(res => {
  14. let location = "";
  15. // saveLocation(
  16. // "江苏省南京市建邺区白龙江东街9号新城科技园科技创新综合体",
  17. // 31.981402,
  18. // 118.737781
  19. // ).then(() => {
  20. // navigation.goBack();
  21. // });
  22. if (res.addressName !== "定位失败") {
  23. location = `${res.location.lat},${res.location.lng}`;
  24. }
  25. webRef.current.injectJavaScript(`window.setLocation('${location}')`);
  26. Portal.remove(key);
  27. });
  28. });
  29. const [chooseLocal, setchooseLocal] = React.useState({});
  30. function showChange(val, title, max, type) {
  31. showDialog({
  32. pla: "",
  33. maxLength: max || 50,
  34. defaultValue: val,
  35. InputType: type,
  36. isEdit: true,
  37. title,
  38. cancelable: true,
  39. confirmCallback: info => {
  40. saveLocation(info, chooseLocal.lat, chooseLocal.lng).then(() => {
  41. navigation.goBack();
  42. });
  43. },
  44. });
  45. }
  46. return (
  47. <WebView
  48. ref={webRef}
  49. source={{
  50. uri: "http://dingdong.izouma.com/map/chooseLocation",
  51. }}
  52. // style={{ flexGrow: 1, width: "100%" }}
  53. onMessage={({ nativeEvent }) => {
  54. const info = JSON.parse(nativeEvent.data);
  55. setchooseLocal({ lat: info.latlng.lat, lng: info.latlng.lng });
  56. showChange(info.poiaddress + info.poiname, "请录入详细地址", 100);
  57. }}
  58. />
  59. );
  60. }