react-native-maps: Error using newLatLngBounds, int,int,int): map size cant be 0
this is my render function :
return (
<MapView
style={styles.map}
region={this.props.lastLocation.LatLng}
>
<MapView.Marker
coordinate={{latitude: 37.78825, longitude: -122.4324,}}
title= 'test'
description = 'test'
/>
</MapView>
);
without the marker everything works fine but when i add the marker i get an error : "Error using newLatLngBounds, int,int,int): map size cant be 0.
looks like it tries to add the marker before the map is loaded .
Any suggestions ?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 23
- Comments: 29 (1 by maintainers)
I’m also having this issue. I have got it to work with:
But I need it to bee 100% of parent height, not the window height.
I have solved this by using : var width = Dimensions.get(‘window’).width; //full width var height = Dimensions.get(‘window’).height; //full height
and flex: 1
In my case specifying the height of map + flex:1 solved the problem.
Still having the same problem on Android. Specifying hardcoded width / height / flex didn’t work. The react view is loaded inside fragment. Not sure if that matters.
Alright I resolved my issue on android, that was more related to
fitToCoordinates.This is due to some kind asynchronism between react and native layout.
My solution: wait for layout with
onLayout(if you just iOS you don’t care) before callingfitToCoordinates:AND ensure (as said above) to tell android precise style for
mapTo finish, please never forget to congratulate or encourage maintainers (doing this on they free time for free) of librairies you use sometimes for commercial applications.
Thank you guys really stunning work in
react-native-maps! 👍@gardner updating to react-native 0.46.4 and react 16.0.0-alpha.12 don’t change anything for me. I have fixed this by removing
flex:1from map style and specifying width and height:In my case I was having the error due to the call to
animateToRegionbefore the map was ready. Using @MacKentoch solution worked for me by using a flag on the state of my component that is set to true on theonLayoutevent.I am seeing this as well running in Android… works fine on iOS
@nonameolsson I made this:
const {height, width} = Dimensions.get('window');for a concise way and ES6 nice looking.
Thanks for your comment, it helped me.
TO whom ever its not working, the solutions provided. They can also try one more thing, Mine MapView is nested, its a children component and down to 4-5 components… My flex 1 + static heights were not working, so i provided flex 1 to parent and window height and width to map and it solved the problem…here is my sameple code…
and about styling
my imports:
Hi, I have same issue after upgrade to RN 0.43.3. Is there any update yet?
Previously I used RN 0.42.3 & react-native-maps 0.13.1. My map is included in a View with flex=1. Before upgrading to RN 0.43.3, this code worked fine:
But after upgrading, same error occurs, only changing
style={{ flex: 1, width: "100%" }}tostyle={{ width: some-hard-code-value, height: "100%" }}can remove the error, but that’s not what I want, same reason with @nonameolsson