React Native Maps - showsUserLocation 不工作

React Native Maps - showsUserLocation not working

我正在使用 React Native Maps 在 ios/Android 上显示地图。

我还没有在 Android 上对其进行适当的测试,但是在 ios 上我无法让 showsUserLocation 道具实际显示位置点。

我已经按照文档进行操作并确保我在 Info.plist 文件中添加了 NSLocationAlwaysAndWhenInUseUsageDescription 和描述。

我的 Info.plist 文件如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    ...
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>We need to access your location to provide location specific points to visit</string>
    ...
</dict>

我的 MapView 是这样初始化的:

<MapView
    provider={PROVIDER_GOOGLE}
    style={styles.map}
    initialRegion={initial}
    mapType={mapType}
    onRegionChange={handleRegionChange}
    onMapReady={() => setRegionReady(true)}
    showsUserLocation={true} // here is what I thought should show it
    showsMyLocationButton={true}
>
    ... // markers rendered here
</MapView>

虽然没有位置点。当应用程序加载时,它会请求查看我已授予的位置的权限,并且我还检查了设置,它应该具有“使用时”的位置访问权限

我也尝试将 Xcode 中的“模拟位置”选项设置为英国伦敦,但它仍然没有显示。

有什么我遗漏的吗?

您需要在模拟器 > 功能 > 位置 > 自定义位置设置中设置您的位置,才能在地图上看到您标记的位置。