【问题标题】:React Native Maps - showsUserLocation not workingReact Native Maps - 显示UserLocation不起作用
【发布时间】:2021-08-12 11:55:01
【问题描述】:

我正在使用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 中的“模拟位置”选项设置为英国伦敦,但仍然不显示。

我有什么遗漏的吗?

【问题讨论】:

  • 您是否在模拟器中设置了您的位置 > 功能 > 位置 > 自定义位置设置?
  • 我没有那套。我现在只是设置它并重新启动并开始一个新的构建,但没有奏效
  • 好的,只需要重新启动 Xcode 和 sim 并再次进行新构建就可以了!谢谢!如果您将其发布为答案,我可以将其标记为正确吗?

标签: react-native react-native-ios react-native-maps location-services


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-22
    相关资源
    最近更新 更多