ดู Document เพิ่มเติมได้ที่ Expo Google Map
เปิดไฟล์ pages/home-page/HomePage.js
ใช้งาน MapView component แทน ใน render()
return (
<MapView
style={{ flex: 1 }}
ref={map => { this.map = map }}
provider={MapView.PROVIDER_GOOGLE}
>
</MapView>
)ผ่าน props initialRegion ของ MapView
ในที่นี่เราดึงตำแหน่งมาจาก Redux ในชื่อของ currentLocation
return (
<MapView
style={{ flex: 1 }}
ref={map => { this.map = map }}
provider={MapView.PROVIDER_GOOGLE}
initialRegion={{
latitude: this.props.currentLocation.coords.latitude,
longitude: this.props.currentLocation.coords.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
>
</MapView>
)return (
<MapView
style={{ flex: 1 }}
ref={map => { this.map = map }}
initialRegion={{
latitude: this.props.currentLocation.coords.latitude,
longitude: this.props.currentLocation.coords.longitude,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
}}
provider={MapView.PROVIDER_GOOGLE}
>
{branches.map(branch => (
<Marker
key={branch.id}
coordinate={{
latitude: branch.position.lat,
longitude: branch.position.lng
}}
title={branch.name}
description={branch.name}
/>
))}
</MapView>
)