react-native-maps: showsMyLocationButton not showing up on Android
Is this a bug report?
YES
Have you read the Installation Instructions?
YES
Environment
react-native: 0.52.0
react: 16.2.0
react-native-maps: 0.19.0
GoogleMaps, but it works on iOS, Android-only issue
Devices:
Huawei Mate 9 running Android 7.0
OnePlus One running Android 5.1.1 (Cyanogen - Factory OS on this phone)
Steps to Reproduce
- Create a MapView, with no options specified
Expected Behavior
showsMyLocationButton to show up
Actual Behavior
showsMyLocationButton not showing up
Reproducible Demo
See https://github.com/react-community/react-native-maps/issues/2003, it has a demo, but it should be reproducible all the time
Other info
I did some digging, on the OnePlus with Android 5 when I call navigator.geolocation.getCurrentPosition (separately) it throws
“Location request timed out” and on the Huawei it never returns. It also never asks for permissions to use my location. I also added every possible location permission one by one to the AndroidManifest, didn’t help.
Could it be related to this? https://github.com/facebook/react-native/issues/7495
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 29
- Comments: 73 (6 by maintainers)
Doesn’t work for me. But it works with margin. Thank you!
And
this.state.marginBottom’s initial value should be 1.I tried @2DKot solution but it doesn’t work for me. After few hours trying everything, I came up with a similar solution:
` constructor(props){ super(props); this.state= { mapMargin:1 } }
setMargin = () => { this.setState({mapMargin:0}) }
<MapView style={{marginBottom: this.state.mapMargin}} region={{ //Put your coords here }} showsUserLocation provider=“google” showsMyLocationButton onMapReady={this.setMargin} > </MapView> ` I tried this in 3 different Android devices and it worked. It should look something like this:
So, on emulator works solution with changing margin, bottom or flex, but on real device for me works only this:
This issue needs an actual fix please
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I have same issue on iOS, using apple map provider. showsMyLocationButton={true} is not showing up the button.
react-native 0.52. react-native-maps 0.20.1
related to this issue#1033 I also faced the same issue and find the workaround here just try to repaint the map with padding or margin of 1. e.g. load your map with some specific coordinates and get the location from
navigator.geolocation.getCurrentPositionand on settings current location on map set just set the map view with padding: 1 or margin: 1 it will show the show my location button.Any ideas when this would be fixed?
You can do something like this.
Then in your mapview, you can put the style referring to the state
<MapView style={{flex: this.state.flex}} />I am using the flex box style property
justifyContent:'center'on the mapView to solve this problem. Works on both android and iOS.I keep seeing this topic, and it’s a lot easier than people are making it out to be. My suggestion is to make it yourself.
Simply:
@davychhouk I’ve tried many different ways since I asked, but it was faster to code my own ShowMyLocation button, but thanks for replying. Can anyone else test this to close the issue?
For me, I notice the button will become visible when I focus on a react-native-elements Input. I have an Input in my header used as a search box and when I tap in it as if I am going to search for something, I notice the “go to current location” button becomes visible. For now I am calling it a “feature” …but it obviously isn’t right. 😉
SDK 32 in expo same problem. Tried all the solution above and they don’t work…
Inside the constructor, add
this.state = { marginBottom : 1 }In case you don’t understand what I’m talking about or want to see some sample code, please read React docs. If you happen to see React code without a constructor, this blog: The constructor is dead, long live the constructor! will clarify you.same the button not showing My environment :
“expo”: “~45.0.0”, “react-native”: “0.68.2”, “react-native-maps”: “0.30.2”,
showsMyLocationButton not showing anything
this my sample code
Can this issue be reopned? What is the point of using library for maps if basic functionality like centering location is not working?
I have tried @JakeHadley code & it worked but I have made few modifications. Instead of
marginBottom, I have just usedmargin& it really worked for me. I am sharing my codes below for your reference.const [mapMargin, setMapMargin] = useState(1)style={{ ...styles.mapView, margin: mapMargin }}onMapReady={setMargin}Maybe the issue is related to showsUserLocation? From the docs, it says “You need to add NSLocationWhenInUseUsageDescription key in Info.plist to enable geolocation, otherwise it is going to fail silently!”
I’m having this issue right now and I haven’t add the key into Info.plist. Plus, I haven’t seen anyone suggesting this, so is it a possibility?
@HarshitMadhav Yup, check here https://imgur.com/37HF6H5, main Q , https://stackoverflow.com/questions/55738286/how-to-fix-show-location-button-in-android-react-native-map
@anastely try the @2DKot solution above, it is still working I have tried and tested it myself.
@2DKot not working for me 😕 Any Update Guys?
Tried the solution @PurnimaNaik was suggesting. On Android Simulator with react-native: 0.57.8 it doesn’t show the button. I was also trying the solutions with marginBottom, paddingBottom and all the others suggested above, but unfortunately on Android Simulator I’m not able to display the button