android - React 本机 MapView 室内关卡选择器适用于 iOS 但不适用于 Android
问题描述
当使用 mapView(react-native-map 库的一部分)时,室内关卡选择器切换适用于 ios 设备,当放大某些建筑物时,但在 android 设备上根本不起作用。
<MapView
style={styles.mapStyle}
provider="google"
showsUserLocation={true}
region={props.region}
zoomEnabled={true}
showsIndoorLevelPicker={true}
showsIndoors={true}
showsMyLocationButton={true}
/>
我如何让它工作?
解决方案
我发现通过在短暂延迟后调整 MapView 组件的大小,我可以让室内地板选择器显示在 Android 上。这是一个带有功能组件的示例。
同样的原则也适用于类组件,但您将使用 setState() 代替。
import React, { useState, useEffect } from 'react';
import { StyleSheet, View } from 'react-native';
import MapView, {
Polygon,
Polyline,
LatLng,
} from 'react-native-maps';
export const Overlays = () => {
const [currentMargin, setCurrentMargin] = useState(1);
useEffect(() => {
setTimeout(() => {
setCurrentMargin(0);
}, 1000);
}, []);
return (
<View style={styles.container}>
<MapView
style={{ marginBottom: currentMargin, ...StyleSheet.absoluteFillObject }}
showsIndoorLevelPicker={true}
showsMyLocationButton={true}
provider={"google"}
initialRegion={{
latitude: 45.497284367030844,
latitudeDelta: 0.0015644580909750516,
longitude: -73.5790109820664,
longitudeDelta: 0.0024069473147392273,
}}
>
</MapView>
</View >
);
}
const styles = StyleSheet.create({
container: {
...StyleSheet.absoluteFillObject,
justifyContent: 'flex-end',
alignItems: 'center',
},
map: {
...StyleSheet.absoluteFillObject,
}
});
export default Overlays;
这是结果! 截屏
希望这可以帮助。
推荐阅读
- node.js - 如何将消息从频道转发到电报机器人上的群组?
- rust - Actix SyncArbiter 注册表
- android - 为什么我的浮动操作按钮在应用启动时会跳到页面顶部?
- ios - iOS检测用户修改设备时钟时间
- c# - Unity Container Registration with Names 不工作,而没有名字工作正常
- swift - 斯威夫特:像 kotlin 一样的接收器关闭?
- sql - 如何计算表中PK的列数(PL-SQL)
- legend - 仅显示饼图图例中的前 5 个值(Am4 图表)
- node.js - Firebase 云函数 firestore 数组 union
- angular - 如何使用 FlexLayout 使文本居中