一个能自定义 Marker 与 InfoWindow 的地图组件;
import QMapView from 'qunar-react-native';
<QMapView
initialRegion={{
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922, // 偏移量
longitudeDelta: 0.0421,
isAboard: true, // 是否在国外
zoom: 14,
coordinateType: 'BD09' //坐标系
}}
/>
getInitialState() {
return {
region: {
latitude: 37.78825,
longitude: -122.4324,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421,
},
};
}
onRegionChange(region) {
this.setState({ region });
}
render() {
return (
<QMapView
region={this.state.region}
onRegionChange={this.onRegionChange}
/>
);
}
import { QMapMarker } from 'quanr-react-native';
<QMapView
region={this.state.region}
onRegionChange={this.onRegionChange}
>
{this.state.markers.map(marker => (
<QMapMarker
coordinate={marker.latlng}
title={marker.title}
description={marker.description}
/>
))}
</QMapView>
<QMapMarker coordinate={marker.latlng}>
<MyCustomMarkerView {...marker} />
</QMapMarker>
<QMapMarker
coordinate={marker.latlng}
image={require('../assets/pin.png')}
/>
import { QMapCallout } from 'react-native-maps';
<QMapMarker coordinate={marker.latlng}>
<MyCustomMarkerView {...marker} />
<QMapCallout>
<MyCustomCalloutView {...marker} />
</QMapCallout>
</QMapMarker>
<QMapView initialRegion={...}>
<QMapMarker draggable
coordinate={this.state.x}
onDragEnd={(e) => this.setState({ x: e.coordinate })}
/>
</QMapView>
要在地图内渲染其他组件,请使用 position: "absolute"
render() {
return (
<QMapView
region={this.state.region}
/>
<OverlayComponent
style={{position: “absolute”, bottom: 50}}
/>
);
}
<QMapView />
与其子组件拥有大量的事件回调,下面的图片将展示一部分回调的 log
更多详细用法,可以参考 qrn-demo
const styles = StyleSheet.create({
map: {
...StyleSheet.absoluteFillObject,
},
});
<QMapView
style={styles.map}
// other props
/>
Bad:
<View>
<TextInput/>
<QMapView/>
</View>
Good:
<View>
<QMapView/>
<TextInput/>
</View>