ExpoAdvanced
expo-location ও react-native-maps
টাস্ক-এ location attach করা ও map view-এ দেখানো।
7টি অংশবাংলা ভাষায়
terminalbash
bash
npx expo install expo-locationimport * as Location from "expo-location";
async function getCurrentPlace() {
const { status } = await Location.requestForegroundPermissionsAsync();
if (status !== "granted") return null;
const pos = await Location.getCurrentPositionAsync({});
const coord = { lat: pos.coords.latitude, lng: pos.coords.longitude };
const places = await Location.reverseGeocodeAsync(coord);
return places[0]?.city ?? places[0]?.name ?? "নিজের স্থান";
}মানচিত্র দেখাতে চাইলে react-native-maps:
terminalbash
bash
npx expo install react-native-mapsimport MapView, { Marker } from "react-native-maps";
<MapView
style={{ flex: 1 }}
initialRegion={{
latitude: task.lat,
longitude: task.lng,
latitudeDelta: 0.01,
longitudeDelta: 0.01,
}}
>
<Marker coordinate={{ latitude: task.lat, longitude: task.lng }} />
</MapView>- foreground permission এই সেটআপেই app config-এ auto-add হয়
- background location — বিশেষ permission, সাবধানে
reverseGeocodeAsync— lat/lng → city/name
map-এর API key
expo-go-এ react-native-maps gratis চলে; standalone build-এ (Android/iOS) নিজের Google Maps API key দরকার — app.config-এ দিন।
শেষ প্যারায় নিজে practice করুন — কোড কপি করে নিজের এডিটরে চালিয়ে দেখুন।