Display user location on react native maps
Asked Answered
G

3

8

How to display user location on React Native Maps

<MapView
    region={this.props.coordinate}
>
    //My map markers
</MapView>
Glary answered 13/7, 2018 at 12:0 Comment(0)
M
27

set showsUserLocation true

<MapView
    region={this.props.coordinate}
    showsUserLocation={true}
  >
    //My map markers
</MapView>
Mccullough answered 13/7, 2018 at 12:7 Comment(4)
Does showUserLocation set to true handle the scenario when user changes location, or one would have to use navigator.getlocation.watchPosition?Valval
You can use followsUserLocation={true} to enable that.Dentition
this won't jump to user's location though, so you have to use Location.getCurrentPositionAsync to get current user location Latitude & Longitude to pass to the MapView region and set the lat/longitude delta to zoom an appropriate amount.Harridan
Don't forget to allow permissions to access locationNadler
S
4

Either you can use property of MapView called showsUserLocation mentioned here

Or you can fetch user location using GeoLocation and display it on Marker

Soothe answered 13/7, 2018 at 12:6 Comment(0)
I
1
<MapView
region={this.props.coordinate}
showsUserLocation={true} >
Imre answered 10/1 at 12:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.