Start at the user current position
See original GitHub issueIt’s not clear from the docs how to set the initial coordinate to be the current location of the user.
The only way I could was by doing something like follows, but it looks too complicated for something that could/should be just a flag such as defaultCenterUserLocation={true}
.
// Looks like centerCoordinate has to be undefined if not set, null won't work
this.state = { initialCoords: undefined }
<MapboxGL.UserLocation
onUpdate={location => {
const currentCoords = [location.coords.longitude, location.coords.latitude]
const initialCoords = this.state.initialCoords
// The idea here is initialCoords should be set only once, otherwise we'll be updating
// the camera's centerCoordinate over and over on every onUpdate(), which causes
// issues when doing camera.flyTo(somewhere_else) or when dragging the map manually
// (the camera will tend to reset its center position to the current position)
this.setState({ initialCoords: initialCoords ? initialCoords : currentCoords })
}}
/>
<MapboxGL.Camera
defaultSettings={{
centerCoordinate: [0, 0],
zoomLevel: 14
}}
centerCoordinate={this.state.initialCoords}
/>
I’m pretty sure it’s not the way to go so please let me know how to do this.
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
Start at the user current position · Issue #560 · rnmapbox/maps
Ie, the center of the map will follow the user position. If you don't want that only set this.setState({ initialCoords: currentCoords }) once....
Read more >how to get user current position as initial location in flutter ...
Give _initialPosition a starting value and then update GoogleMap when _initialPosition has been updated. Share.
Read more >Geolocation: Displaying User or Device Position on Maps
This tutorial shows you how to display the geographic location of a user or device on a Google ... Below is a map...
Read more >Get user's current location in android || Android studio tutorial
In This Video you will learn how to get user's current location with the help of gps in android.We will not use fusedlocationproviderclient ......
Read more >Geolocation.getCurrentPosition() - Web APIs | MDN
The Geolocation.getCurrentPosition() method is used to get the current position of the device.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
<MapboxGL.UserLocation ref={(location) => {console.log({location})}} /> then you can get corrent location and use the ref of camera method this.camera.moveTo([lng, lat])
You guys can just use
<MapboxGL.Camera followUserLocation={true} />