在CreateForm中使用mapView时出现奇怪的行为。

huangapple go评论77阅读模式
英文:

Strange behaviour with mapView in CreateForm

问题

我今天遇到了与React Native相关的问题,具体是我遇到的奇怪行为。问题与地图(Map)有关。当我点击地图上的某个位置并设置一个标记时,它可以正常工作。但是当我想在其他地方放置标记时,它却不起作用。当我保存标记位置等信息并返回时,地图显示的是之前的图像,而不是带有标记的图像。下面是我发送的代码:

import React, { useEffect, useLayoutEffect, useState } from "react";
import {
  launchImageLibraryAsync,
  useMediaLibraryPermissions,
} from "expo-image-picker";
import * as Location from "expo-location";
import {
  Alert,
  Dimensions,
  Image,
  Pressable,
  ScrollView,
  Text,
  TextInput,
  View,
} from "react-native";
import MapView, { Marker } from "react-native-maps";
import MaterialCommunityIcons from "react-native-vector-icons/MaterialCommunityIcons";
import IonIcons from "@expo/vector-icons/Ionicons";
import DateTimePicker from "@react-native-community/datetimepicker";
import { useIsFocused } from "@react-navigation/native";

const CreateForm = ({ navigation, route }) => {
  const [isOpened, setIsOpened] = useState(false);
  const [isEndOpened, setIsEndOpened] = useState(false);
  const [date, setDate] = useState(new Date());
  const [dateTitle, setDateTitle] = useState(null);
  const [endDate, setEndDate] = useState(new Date());
  const [endDateTitle, setEndDateTitle] = useState(null);
  const [finalImages, setFinalImages] = useState([]);
  const [currentLocation, setCurrentLocation] = useState(null);
  const [markerCoords, setMarkerCoords] = useState(null);

  const isFocused = useIsFocused();

  useEffect(() => {
    if (route.params && isFocused) {
      setCurrentLocation(route.params.mapLayout);
      setMarkerCoords(route.params.markerCoords);
    }
  }, [route, isFocused]);

  const getLocationPermission = async () => {
    let { status } = await Location.requestForegroundPermissionsAsync();
    if (status !== "granted") {
      setErrorMsg("Permission to access location was denied");
      return;
    }

    let location = await Location.getCurrentPositionAsync();
    console.log(location);

    const locationObject = {
      latitude: location.coords.latitude,
      longitude: location.coords.longitude,
      latitudeDelta: 0.0043,
      longitudeDelta: 0.0034,
    };

    setCurrentLocation(locationObject);
  };

  const [status, requestPermission] = useMediaLibraryPermissions();
  useLayoutEffect(() => {
    navigation.setOptions({
      title: "New Travel story",
      headerRight: () => {},
    });
  }, []);

  const openModal = () => {
    setIsOpened(true);
  };

  const endModalOpen = () => {
    setIsEndOpened(true);
  };

  const selectImages = async () => {
    if (status.granted) {
      const imageLibrary = await launchImageLibraryAsync({
        allowsMultipleSelection: true,
      });
      if (imageLibrary.assets === null) {
        setFinalImages([]);
        return;
      }

      const allImages = [...finalImages, ...imageLibrary.assets];

      if (allImages.length > 15) {
        Alert.alert(
          "Amount of pictures exceeded !",
          "You are able only to add 15 pictures, in order not letting the app to break up. If you'd like to change all Images, click the button and choose again."
        );
        setFinalImages((prev) => {
          const maxAmount = prev.slice(0, 15);
          return [...maxAmount];
        });

        return;
      }

      setFinalImages((prev) => {
        return [...prev, ...imageLibrary.assets];
      });
    } else {
      await requestPermission();
    }
  };

  const navigateToMapSelect = () => {
    navigation.navigate("MapSelect", {
      coords: currentLocation,
      marker: markerCoords ? markerCoords : null,
    });
  };

  return (
    <ScrollView contentContainerStyle={{ padding: 16 }}>
      <Text style={{ textAlign: "center", fontSize: 24, fontWeight: "500" }}>
        Prepend a new Travel story{" "}
        <IonIcons name="airplane-sharp" style={{ fontSize: 16 }} />
      </Text>
      <Text style={{ textAlign: "center", fontWeight: "300" }}>
        And save the memories forever{" "}
        <IonIcons name="infinite-sharp" style={{ fontSize: 24 }} />
      </Text>
      <View style={{ padding: 5 }}>
        <View>
          <Text>Place Name:</Text>
          <TextInput
            style={{
              backgroundColor: "black",
              padding: 5,
              borderRadius: 5,
              color: "white",
            }}
            placeholder="Type the name of the travel-place"
            placeholderTextColor="gray"
          />
        </View>

        <View>
          <Text>Description:</Text>
          <TextInput
            multiline
            placeholder="Type the description"
            style={{
              backgroundColor: "black",
              padding: 5,
              borderRadius: 5,
              color: "white",
            }}
            placeholderTextColor="gray"
          />
        </View>

        <View style={{ gap: 6, padding: 5, justifyContent: "space-between" }}>
          <View>
            <Text>Travel start:{dateTitle}</Text>
            <Pressable
              style={{
                backgroundColor: "black",
                borderRadius: 4,
                padding: 6,
              }}
              android_ripple={{ color: "gray" }}
              onPress={openModal}
            >
              <Text style={{ color: "white" }}>Select time</Text>
            </Pressable>
            {isOpened && (
              <DateTimePicker
                value={date ? date : new Date()}
                onChange={(e) => {
                  setDate(new Date(e.nativeEvent.timestamp));
                  console.log(new Date(e.nativeEvent.timestamp));
                  setDateTitle(new Date(e.nativeEvent.timestamp).toUTCString());
                  setIsOpened(false);
                }}
              />
            )}
          </View>

          <View>
            <Text>Travel end:{endDateTitle}</Text>
            <Pressable
              style={{ backgroundColor: "black", borderRadius: 4, padding: 6 }}
              android_ripple={{ color: "gray" }}
              onPress={endModalOpen}
            >
              <Text style={{ color: "white" }}>Select time</Text>
            </Pressable>
            {isEndOpened && (
              <DateTimePicker
                value={endDate ? endDate : new Date()}
                onChange={(e) => {
                  setEndDate(new Date(e.nativeEvent.timestamp));
                  console.log(new Date(e.nativeEvent.timestamp));
                  setEndDateTitle(
                    new Date(e.nativeEvent.timestamp).toUTCString()
                  );
                  setIsEndOpened(false);
                }}
              />
            )}
          </View>
        </View>

        <View>
          <Pressable
            style={{
              backgroundColor: "black",
              borderRadius: 4,
              padding: 6,
              margin: 12,
            }}
            android_ripple={{ color: "gray" }}
            onPress={selectImages}
          >
            <Text style={{ color: "white" }}>
              Select Images <MaterialCommunityIcons name="camera" />
            </Text>
          </Pressable>
        </View>

        {finalImages.length === 0 && (
          <Text style={{ textAlign: "center" }}>
            You haven't picked any image yet 😥
          </Text>
        )}

        {finalImages.length > 0 && (
          <>
            <Text
              style={{
                fontWeight: "600",
                textAlign: "center",
                verticalAlign: "middle",
                margin: 4,
              }}
            >
              You have picked already {finalImages.length} pictures 😊
            </Text>

            <View
              style={{
                gap: 6,
                flexWrap: "wrap",
                flexDirection: "row",
                justifyContent: "center",
              }}
            >
              {finalImages.map((image, index) => (
                <Image
                  key={index}
                  source={{ uri: image.uri }}
                  style={{
                    width: 50,
                    height: 50,
                    objectFit: "cover",
                    margin: 5,
                  }}
                />
              ))}
            </View>
          </>
        )}

        <View>
          <Text style={{ fontWeight: "600", padding: 6, textAlign: "center" }}>
            Choose the place on map that you visited:
          </Text>
          <MapView
            scrollEnabled={false}
            zoomEnabled={false}
            initialRegion={currentLocation}
            style={{
              width: "100%",
              height: Dimensions.get("window").height / 3,
            }}
          >
            {markerCoords && <Marker coordinate={markerCoords} />}
          </MapView>

          <View
            style={{
              flexDirection: "row",
              justifyContent: "space-around",
              gap: 6,
            }}
          >
            <Pressable
              onPress={getLocationPermission}
              android_ripple={{ color: "gray" }}
              style={{
                padding: 5,
                margin: 5,
                backgroundColor: "black",
                alignItems: "center",
                borderRadius: 5,
              }}
            >
              <Text style={{ color: "white" }}>
                Share Your Location{" "}
                <IonIcons name="location" style={{ fontSize: 16 }} />
              </Text>
            </Pressable>

            <Pressable
              onPress={navigateToMapSelect}
              android_ripple={{ color: "gray" }}
              style={{
                padding: 5,
                margin: 5,
                backgroundColor: "black",
                alignItems: "center",
                borderRadius: 5,
              }}
            >
              <Text style={{ color: "white" }}>
                Select on Map <IonIcons name="map" style={{ fontSize: 16 }} />
              </Text>
            </Pressable>
          </View>
        </View>

        <Pressable
          style={{ backgroundColor: "black", padding: 6, borderRadius: 4 }}
          onPress={() => {
            console.log(route.params);
          }}
        >
          <Text style={{ color: "white", textAlign: "center" }}>Submit</Text>
        </Pressable>
      </View>
    </ScrollView>
  );
};

export default CreateForm;
import React, { useEffect, useState } from "react";
import { Pressable, Text, View } from "react-native";
import MapView, { Marker } from "react-native-maps";
import IonIcons from "@expo/vector-icons/Ionicons";

const MapSelect = ({ route, navigation }) => {
  const [markerCoords, setMarkerCoords] = useState(null);
  const [newMapLayout, setNewMapLayout] = useState(null);
  const coordsForMap = route.params.coords;
  const existingMarkerCoords = route.params.marker;

  const selectPlaceOnMap = (e) => {
    const coords = e.nativeEvent.coordinate;

    const newMapsCoords = {
      latitude: coords.latitude,
      longitude: coords.longitude,
      latitudeDelta: 0.0922,
      longitudeDelta: 0.0421,
    };
    setNewMapLayout(newMapsCoords);
    setMarkerCoords(coords);

    console.log(newMapsCoords);
    console.log(coords);
  };

  const saveMarker = () => {
    navigation.navigate("StackScreen", {
      mapLayout: newMapLayout,
      markerCoords: markerCoords,
    });
  };

  useEffect(() => {
    if (existingMarkerCoords) {
      setMarkerCoords(existingMarkerCoords);
    }
  }, [existingMarkerCoords]);

  useEffect(() => {
    navigation.setOptions({
      headerRight: () => (
        <Pressable onPress={saveMarker}>
          <Text style={{ color: "white" }}>
            Save <IonIcons name="save-sharp" />
          </Text>
        </Pressable>
      ),
    });
  }, [saveMarker]); // Listen to changes in newMapLayout and markerCoords

  return (
    <View>
      <MapView
        initialRegion={coordsForMap}
        style={{ width: "100%", height: "100%" }}
        onPress={selectPlaceOnMap}
      >
        {markerCoords && <Marker coordinate={markerCoords} />}
      </MapView>
    </View>
  );
};

export default MapSelect;

我尽力了,但实际上我的尝试没有成功。所以我期望在保存标记后,MapView会显示带有标记的地点。

英文:

i come today with issue related to react-native and namely the strange behaviour i encountered. So, the issue is sorely connected with Map. When I click to select on Map a place and set a marker it does it. But when i want to place the marker somewhere else and i do it. When I save the marker position etc. and come back, the previous image of the map is displayed and not the one with marker. Below I've sent the code:

import React, { useEffect, useLayoutEffect, useState } from &quot;react&quot;;
import {
launchImageLibraryAsync,
useMediaLibraryPermissions,
} from &quot;expo-image-picker&quot;;
import * as Location from &quot;expo-location&quot;;
import {
Alert,
Dimensions,
Image,
Pressable,
ScrollView,
Text,
TextInput,
View,
} from &quot;react-native&quot;;
import MapView, { Marker } from &quot;react-native-maps&quot;;
import MaterialCommunityIcons from &quot;react-native-vector-icons/MaterialCommunityIcons&quot;;
import IonIcons from &quot;@expo/vector-icons/Ionicons&quot;;
import DateTimePicker from &quot;@react-native-community/datetimepicker&quot;;
import { useIsFocused } from &quot;@react-navigation/native&quot;;
const CreateForm = ({ navigation, route }) =&gt; {
const [isOpened, setIsOpened] = useState(false);
const [isEndOpened, setIsEndOpened] = useState(false);
const [date, setDate] = useState(new Date());
const [dateTitle, setDateTitle] = useState(null);
const [endDate, setEndDate] = useState(new Date());
const [endDateTitle, setEndDateTitle] = useState(null);
const [finalImages, setFinalImages] = useState([]);
const [currentLocation, setCurrentLocation] = useState(null);
const [markerCoords, setMarkerCoords] = useState(null);
const isFocused = useIsFocused();
useEffect(() =&gt; {
if (route.params &amp;&amp; isFocused) {
setCurrentLocation(route.params.mapLayout);
setMarkerCoords(route.params.markerCoords);
}
}, [route, isFocused]);
const getLocationPermission = async () =&gt; {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== &quot;granted&quot;) {
setErrorMsg(&quot;Permission to access location was denied&quot;);
return;
}
let location = await Location.getCurrentPositionAsync();
console.log(location);
const locationObject = {
latitude: location.coords.latitude,
longitude: location.coords.longitude,
latitudeDelta: 0.0043,
longitudeDelta: 0.0034,
};
setCurrentLocation(locationObject);
};
const [status, requestPermission] = useMediaLibraryPermissions();
useLayoutEffect(() =&gt; {
navigation.setOptions({
title: &quot;New Travel story&quot;,
headerRight: () =&gt; {},
});
}, []);
const openModal = () =&gt; {
setIsOpened(true);
};
const endModalOpen = () =&gt; {
setIsEndOpened(true);
};
const selectImages = async () =&gt; {
if (status.granted) {
const imageLibrary = await launchImageLibraryAsync({
allowsMultipleSelection: true,
});
if (imageLibrary.assets === null) {
setFinalImages([]);
return;
}
const allImages = [...finalImages, ...imageLibrary.assets];
if (allImages.length &gt; 15) {
Alert.alert(
&quot;Amount of pictures exceeded !&quot;,
&quot;You are able only to add 15 pictures, in order not letting the app to break up. If you&#39;d like to change all Images, click the button and choose again.&quot;
);
setFinalImages((prev) =&gt; {
const maxAmount = prev.slice(0, 15);
return [...maxAmount];
});
return;
}
setFinalImages((prev) =&gt; {
return [...prev, ...imageLibrary.assets];
});
} else {
await requestPermission();
}
};
const navigateToMapSelect = () =&gt; {
navigation.navigate(&quot;MapSelect&quot;, {
coords: currentLocation,
marker: markerCoords ? markerCoords : null,
});
};
return (
&lt;ScrollView contentContainerStyle={{ padding: 16 }}&gt;
&lt;Text style={{ textAlign: &quot;center&quot;, fontSize: 24, fontWeight: &quot;500&quot; }}&gt;
Prepend a new Travel story{&quot; &quot;}
&lt;IonIcons name=&quot;airplane-sharp&quot; style={{ fontSize: 16 }} /&gt;
&lt;/Text&gt;
&lt;Text style={{ textAlign: &quot;center&quot;, fontWeight: &quot;300&quot; }}&gt;
And save the memories forever{&quot; &quot;}
&lt;IonIcons name=&quot;infinite-sharp&quot; style={{ fontSize: 24 }} /&gt;
&lt;/Text&gt;
&lt;View style={{ padding: 5 }}&gt;
&lt;View&gt;
&lt;Text&gt;Place Name:&lt;/Text&gt;
&lt;TextInput
style={{
backgroundColor: &quot;black&quot;,
padding: 5,
borderRadius: 5,
color: &quot;white&quot;,
}}
placeholder=&quot;Type the name of the travel-place&quot;
placeholderTextColor=&quot;gray&quot;
/&gt;
&lt;/View&gt;
&lt;View&gt;
&lt;Text&gt;Description:&lt;/Text&gt;
&lt;TextInput
multiline
placeholder=&quot;Type the description&quot;
style={{
backgroundColor: &quot;black&quot;,
padding: 5,
borderRadius: 5,
color: &quot;white&quot;,
}}
placeholderTextColor=&quot;gray&quot;
/&gt;
&lt;/View&gt;
&lt;View style={{ gap: 6, padding: 5, justifyContent: &quot;space-between&quot; }}&gt;
&lt;View&gt;
&lt;Text&gt;Travel start:{dateTitle}&lt;/Text&gt;
&lt;Pressable
style={{
backgroundColor: &quot;black&quot;,
borderRadius: 4,
padding: 6,
}}
android_ripple={{ color: &quot;gray&quot; }}
onPress={openModal}
&gt;
&lt;Text style={{ color: &quot;white&quot; }}&gt;Select time&lt;/Text&gt;
&lt;/Pressable&gt;
{isOpened &amp;&amp; (
&lt;DateTimePicker
value={date ? date : new Date()}
onChange={(e) =&gt; {
setDate(new Date(e.nativeEvent.timestamp));
console.log(new Date(e.nativeEvent.timestamp));
setDateTitle(new Date(e.nativeEvent.timestamp).toUTCString());
setIsOpened(false);
}}
/&gt;
)}
&lt;/View&gt;
&lt;View&gt;
&lt;Text&gt;Travel end:{endDateTitle}&lt;/Text&gt;
&lt;Pressable
style={{ backgroundColor: &quot;black&quot;, borderRadius: 4, padding: 6 }}
android_ripple={{ color: &quot;gray&quot; }}
onPress={endModalOpen}
&gt;
&lt;Text style={{ color: &quot;white&quot; }}&gt;Select time&lt;/Text&gt;
&lt;/Pressable&gt;
{isEndOpened &amp;&amp; (
&lt;DateTimePicker
value={endDate ? endDate : new Date()}
onChange={(e) =&gt; {
setEndDate(new Date(e.nativeEvent.timestamp));
console.log(new Date(e.nativeEvent.timestamp));
setEndDateTitle(
new Date(e.nativeEvent.timestamp).toUTCString()
);
setIsEndOpened(false);
}}
/&gt;
)}
&lt;/View&gt;
&lt;/View&gt;
&lt;View&gt;
&lt;Pressable
style={{
backgroundColor: &quot;black&quot;,
borderRadius: 4,
padding: 6,
margin: 12,
}}
android_ripple={{ color: &quot;gray&quot; }}
onPress={selectImages}
&gt;
&lt;Text style={{ color: &quot;white&quot; }}&gt;
Select Images &lt;MaterialCommunityIcons name=&quot;camera&quot; /&gt;
&lt;/Text&gt;
&lt;/Pressable&gt;
&lt;/View&gt;
{finalImages.length === 0 &amp;&amp; (
&lt;Text style={{ textAlign: &quot;center&quot; }}&gt;
You haven&#39;t picked any image yet &#128549;
&lt;/Text&gt;
)}
{finalImages.length &gt; 0 &amp;&amp; (
&lt;&gt;
&lt;Text
style={{
fontWeight: &quot;600&quot;,
textAlign: &quot;center&quot;,
verticalAlign: &quot;middle&quot;,
margin: 4,
}}
&gt;
You have picked already {finalImages.length} pictures &#128558;
&lt;/Text&gt;
&lt;View
style={{
gap: 6,
flexWrap: &quot;wrap&quot;,
flexDirection: &quot;row&quot;,
justifyContent: &quot;center&quot;,
}}
&gt;
{finalImages.map((image, index) =&gt; (
&lt;Image
key={index}
source={{ uri: image.uri }}
style={{
width: 50,
height: 50,
objectFit: &quot;cover&quot;,
margin: 5,
}}
/&gt;
))}
&lt;/View&gt;
&lt;/&gt;
)}
&lt;View&gt;
&lt;Text style={{ fontWeight: &quot;600&quot;, padding: 6, textAlign: &quot;center&quot; }}&gt;
Choose the place on map that you visited:
&lt;/Text&gt;
&lt;MapView
scrollEnabled={false}
zoomEnabled={false}
initialRegion={currentLocation}
style={{
width: &quot;100%&quot;,
height: Dimensions.get(&quot;window&quot;).height / 3,
}}
&gt;
{markerCoords &amp;&amp; &lt;Marker coordinate={markerCoords} /&gt;}
&lt;/MapView&gt;
&lt;View
style={{
flexDirection: &quot;row&quot;,
justifyContent: &quot;space-around&quot;,
gap: 6,
}}
&gt;
&lt;Pressable
onPress={getLocationPermission}
android_ripple={{ color: &quot;gray&quot; }}
style={{
padding: 5,
margin: 5,
backgroundColor: &quot;black&quot;,
alignItems: &quot;center&quot;,
borderRadius: 5,
}}
&gt;
&lt;Text style={{ color: &quot;white&quot; }}&gt;
Share Your Location{&quot; &quot;}
&lt;IonIcons name=&quot;location&quot; style={{ fontSize: 16 }} /&gt;
&lt;/Text&gt;
&lt;/Pressable&gt;
&lt;Pressable
onPress={navigateToMapSelect}
android_ripple={{ color: &quot;gray&quot; }}
style={{
padding: 5,
margin: 5,
backgroundColor: &quot;black&quot;,
alignItems: &quot;center&quot;,
borderRadius: 5,
}}
&gt;
&lt;Text style={{ color: &quot;white&quot; }}&gt;
Select on Map &lt;IonIcons name=&quot;map&quot; style={{ fontSize: 16 }} /&gt;
&lt;/Text&gt;
&lt;/Pressable&gt;
&lt;/View&gt;
&lt;/View&gt;
&lt;Pressable
style={{ backgroundColor: &quot;black&quot;, padding: 6, borderRadius: 4 }}
onPress={() =&gt; {
console.log(route.params);
}}
&gt;
&lt;Text style={{ color: &quot;white&quot;, textAlign: &quot;center&quot; }}&gt;Submit&lt;/Text&gt;
&lt;/Pressable&gt;
&lt;/View&gt;
&lt;/ScrollView&gt;
);
};
export default CreateForm;
import React, { useEffect, useState } from &quot;react&quot;;
import { Pressable, Text, View } from &quot;react-native&quot;;
import MapView, { Marker } from &quot;react-native-maps&quot;;
import IonIcons from &quot;@expo/vector-icons/Ionicons&quot;;
const MapSelect = ({ route, navigation }) =&gt; {
const [markerCoords, setMarkerCoords] = useState(null);
const [newMapLayout, setNewMapLayout] = useState(null);
const coordsForMap = route.params.coords;
const existingMarkerCoords = route.params.marker;
const selectPlaceOnMap = (e) =&gt; {
const coords = e.nativeEvent.coordinate;
const newMapsCoords = {
latitude: coords.latitude,
longitude: coords.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
};
setNewMapLayout(newMapsCoords);
setMarkerCoords(coords);
console.log(newMapsCoords);
console.log(coords);
};
const saveMarker = () =&gt; {
navigation.navigate(&quot;StackScreen&quot;, {
mapLayout: newMapLayout,
markerCoords: markerCoords,
});
};
useEffect(() =&gt; {
if (existingMarkerCoords) {
setMarkerCoords(existingMarkerCoords);
}
}, [existingMarkerCoords]);
useEffect(() =&gt; {
navigation.setOptions(
{
headerRight: () =&gt; (
&lt;Pressable onPress={saveMarker}&gt;
&lt;Text style={{ color: &quot;white&quot; }}&gt;
Save &lt;IonIcons name=&quot;save-sharp&quot; /&gt;
&lt;/Text&gt;
&lt;/Pressable&gt;
),
},
[]
);
}, [saveMarker]); // Listen to changes in newMapLayout and markerCoords
return (
&lt;View&gt;
&lt;MapView
initialRegion={coordsForMap}
style={{ width: &quot;100%&quot;, height: &quot;100%&quot; }}
onPress={selectPlaceOnMap}
&gt;
{markerCoords &amp;&amp; &lt;Marker coordinate={markerCoords} /&gt;}
&lt;/MapView&gt;
&lt;/View&gt;
);
};
export default MapSelect;

Well i did all my best, but actually my attempts didn't work. So I expect that after I save the marker, the MapView will display the place with the marker.

答案1

得分: 0

我已经修复了,唯一需要的是设置region。我猜今晚我不会清醒!

在initialRegion之后添加region!

 <View>
<Text style={{ fontWeight: "600", padding: 6, textAlign: "center" }}>
选择你访问的地图上的位置:
</Text>
<MapView
scrollEnabled={false}
zoomEnabled={false}
initialRegion={initalCoords}
region={currentLocation}
style={{
width: "100%",
height: Dimensions.get("window").height / 3,
}}
>
{markerCoords && <Marker coordinate={markerCoords} />}
</MapView>
<View
style={{
flexDirection: "row",
justifyContent: "space-around",
gap: 6,
}}
>
<Pressable
onPress={getLocationPermission}
android_ripple={{ color: "gray" }}
style={{
padding: 5,
margin: 5,
backgroundColor: "black",
alignItems: "center",
borderRadius: 5,
}}
>
<Text style={{ color: "white" }}>
分享你的位置{" "}
<IonIcons name="location" style={{ fontSize: 16 }} />
</Text>
</Pressable>
<Pressable
onPress={navigateToMapSelect}
android_ripple={{ color: "gray" }}
style={{
padding: 5,
margin: 5,
backgroundColor: "black",
alignItems: "center",
borderRadius: 5,
}}
>
<Text style={{ color: "white" }}>
在地图上选择 <IonIcons name="map" style={{ fontSize: 16 }} />
</Text>
</Pressable>
</View>
</View>
英文:

I FIXED IT, THE ONLY THING NEEDED WAS TO SET region. I reckon I won't be sober this night !

BEYOND INITIALREGION ADD region !

 &lt;View&gt;
&lt;Text style={{ fontWeight: &quot;600&quot;, padding: 6, textAlign: &quot;center&quot; }}&gt;
Choose the place on map that you visited:
&lt;/Text&gt;
&lt;MapView
scrollEnabled={false}
zoomEnabled={false}
initialRegion={initalCoords}
region={currentLocation}
style={{
width: &quot;100%&quot;,
height: Dimensions.get(&quot;window&quot;).height / 3,
}}
&gt;
{markerCoords &amp;&amp; &lt;Marker coordinate={markerCoords} /&gt;}
&lt;/MapView&gt;
&lt;View
style={{
flexDirection: &quot;row&quot;,
justifyContent: &quot;space-around&quot;,
gap: 6,
}}
&gt;
&lt;Pressable
onPress={getLocationPermission}
android_ripple={{ color: &quot;gray&quot; }}
style={{
padding: 5,
margin: 5,
backgroundColor: &quot;black&quot;,
alignItems: &quot;center&quot;,
borderRadius: 5,
}}
&gt;
&lt;Text style={{ color: &quot;white&quot; }}&gt;
Share Your Location{&quot; &quot;}
&lt;IonIcons name=&quot;location&quot; style={{ fontSize: 16 }} /&gt;
&lt;/Text&gt;
&lt;/Pressable&gt;
&lt;Pressable
onPress={navigateToMapSelect}
android_ripple={{ color: &quot;gray&quot; }}
style={{
padding: 5,
margin: 5,
backgroundColor: &quot;black&quot;,
alignItems: &quot;center&quot;,
borderRadius: 5,
}}
&gt;
&lt;Text style={{ color: &quot;white&quot; }}&gt;
Select on Map &lt;IonIcons name=&quot;map&quot; style={{ fontSize: 16 }} /&gt;
&lt;/Text&gt;
&lt;/Pressable&gt;
&lt;/View&gt;
&lt;/View&gt;

huangapple
  • 本文由 发表于 2023年8月8日 23:33:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76861073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定