简体   繁体   English

FollowsUserLocation 不适用于 Android (react-native-maps)

[英]FollowsUserLocation not working on Android (react-native-maps)

The map follows the user's location on iOS, but not on Android.地图会在 iOS 上跟随用户的位置,但在 Android 上不会。 The user's location is shown on the map, and the "my location" button also works just fine.用户的位置显示在地图上,“我的位置”按钮也可以正常工作。

What could be the issue for the Android to not follow location? Android 不跟踪位置可能是什么问题?

<MapView
  style={styles.map, { flex: 1, marginBottom: this.state.marginBottom }}
  onMapReady={this._onMapReady}
  initialRegion={initialRegion}
  showsUserLocation={true}
  followsUserLocation={true}
  showsMyLocationButton={true}
>

react-native-maps: 0.21.0反应原生地图:0.21.0

react: 16.4.1反应:16.4.1

package.json:包.json:

{
  ...
  },
  "dependencies": {
    "@mapbox/polyline": "^1.0.0",
    "@turf/turf": "^5.1.6",
    "axios": "^0.18.0",
    "moment": "^2.22.2",
    "react": "16.4.1",
    "react-moment": "^0.8.3",
    "react-native": "0.56.1",
    "react-native-background-geolocation-android": "git+ssh://git@github.com/transistorsoft/react-native-background-geolocation-android.git",
    "react-native-easy-toast": "^1.1.0",
    "react-native-firebase": "^4.3.8",
    "react-native-iphone-x-helper": "^1.1.0",
    "react-native-maps": "^0.21.0",
    "react-native-navigation": "^2.0.2641",
    "react-native-sound": "^0.10.9",
    "react-native-sound-player": "^0.5.3",
    "react-native-speech": "^0.1.2",
    "react-native-splash-screen": "^3.1.1",
    "react-native-svg": "^7.0.2",
    "react-native-svg-uri": "^1.2.3",
    "react-native-tts": "^2.0.0",
    "react-native-view-overflow": "0.0.3",
    "react-redux": "^5.0.7",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0",
    "styled-components": "^3.4.6"
  },
  "devDependencies": {
    "babel-jest": "23.6.0",
    "babel-preset-react-native": "5.0.2",
    "jest": "23.6.0",
    "react-test-renderer": "16.4.1",
    "redux-devtools-extension": "^2.13.5",
    "remote-redux-devtools": "^0.5.13"
  },
  "jest": {
    "preset": "react-native"
  }
}

I managed to solve this problem following this https://github.com/react-community/react-native-maps/issues/1038#issuecomment-404223242 .我设法按照这个https://github.com/react-community/react-native-maps/issues/1038#issuecomment-404223242解决了这个问题。 This is exactly what I wanted to implement.这正是我想要实现的。 The map follows the user location by default, but will disable following when the map is dragged.地图默认跟随用户位置,但在拖动地图时将禁用跟随。

Then I created a button for the current location following this https://github.com/react-community/react-native-maps/issues/209#issuecomment-350907665 .然后我在https://github.com/react-community/react-native-maps/issues/209#issuecomment-350907665之后为当前位置创建了一个按钮。 Made the button set followsUserLocation back to true.使按钮设置 followUserLocation 回到 true。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM