1.首先安裝配置
npm i react-native-amap3d
react-native link react-native-amap3d
2.在AndroidManifest.xml 文件中添加key
<application>
<meta-data
android:name="com.amap.api.v2.apikey"
android:value="你的高德 Key" />
</application>
3.在js 文件中導(dǎo)入地圖模塊
import { MapView } from 'react-native-amap3d'
4.設(shè)置地圖狀態(tài)
所謂的地圖狀態(tài)包括:中心坐標(biāo)(coordinate)抒蚜、縮放級別(zoomLevel)、傾斜度(titl)、旋轉(zhuǎn)角度(rotation)、顯示區(qū)域(region)逾雄、地圖模式(mapType)祠丝。目前高德地圖支持5種地圖模式:
標(biāo)準(zhǔn)(standard)
衛(wèi)星(satellite)
導(dǎo)航(navigation)
公交(bus)
夜間(night)
<MapView
style={StyleSheet.absoluteFill}
coordinate={{
latitude: 39.90980,
longitude: 116.37296,
}}
zoomLevel={18}
tilt={45}
rotation={45}
region={{
latitude: 39.90980,
longitude: 116.37296,
latitudeDelta: 0.1,
longitudeDelta: 0.1,}}
mapType='navigation'
showsIndoorMap
/>
5.定位
<MapView
style={StyleSheet.absoluteFill}
zoomLevel={18}
tilt={45}
mapType='standard'
locationInterval={10000} //定位間隔(ms)年碘,默認 2000
distanceFilter={10} //定位的最小更新距離
locationEnabled={true} //開啟定位
showslocationbutton={true}
showsCompass={true}
showsscale={true}
showsTraffic={true}
region={{
latitude: this.state.mLatitude,
longitude: this.state.mLongitude,
latitudeDelta: 0.1,
longitudeDelta: 0.1,
}}
//onlocation 啟動定位顯示 regison 中的顯示區(qū)域
onlocation={({nativeEvent}) =>this.setState({
mLatitude: nativeEvent.latitude,
mLongitude: nativeEvent.longitude,
})}
//onLocation={({nativeEvent}) =>{this.toPosition(nativeEvent)}}
/>