-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error on using fitToElements #180
Comments
Whats the data in |
let markers = [{
latlng: {
latitude: this.props.currentBooking.pickup_latitude,
longitude: this.props.currentBooking.pickup_longitude
},
image: require('../images/customer.png')
}, {
latlng: {
latitude: this.props.driverLocation.latitude,
longitude: this.props.driverLocation.longitude
},
image: require('../images/onway.png')
}]; Latitude and Longitude are string value... I think it supposed to be a Point... Let me know if I am correct and Thanks for reply |
Not sure if thats the issue but can you cast the latitude and longitude to a float? |
I cast the latitude and longitude to a float but getting the same error "No included points". Can you please explain where should I mention points and what would be the values (x and y) to be passed in Point? Let me clarify one more thing is that I am working on Android. |
The docs says |
I found the solution, you just have to add an empty js object, like this: |
@DennisMG |
@simonhintersonnleitner I thought it solved the problem but sometimes throws the error described above and other times works perfectly |
try changing the fitToElements function in react-native-maps/android/src/main/java/com/AirMaps/AirMapView.java for this:
It worked for me. |
@DennisMG : Yeah, above change prevent it from a crash but found fitToElements is not working. I am calling this method in componentDidMount but doesn't look map is adjusting zoom level. |
👍 Anyone able to fix this? |
I feel like this is a required feature for any map with markers or am I the only one? |
I've come into this as well. Adding some logging to In fact, when configuring my component to quickly render several times (intentionally updating state during render to trigger a tight loop), we can cycle through many This indicates we can't depend on component lifecycle methods like If I haven't made a bad assumption, it looks like the cleanest fix would be to replace I.e., render() {
var markers = this.props.markers || [];
return (
<MapView
style={[styles.map, this.props.mapStyle]}
fitToElements={MapView.ANIMATED_FIT} // or MapView.IMMEDIATE_FIT
initialRegion={this.getInitialRegion(markers)}>
{markers.map(marker => (
<MapView.Marker
coordinate={marker.latlng}
title={marker.title}
description={marker.description}
image={marker.image}/>
))}
</MapView>
);
} |
@igrayson We actually just need a |
I don't believe that would help. The map is rendered (and becomes 'ready') before any children/markers are added. Markers are later added one at a time (via We need to know when the map is rendered, and all children have been added -- i.e., what you normally expect |
We haven't found a consistent workaround for this yet. Has anyone found a reliable way to |
In my desperation I used the setTimeout function.. setTimeout(() => {
this._map.fitToElements(false);
}, 1000); which worked for me, but it feels so hacky and I hope I can remove it asap. |
Hmm I'm new to RN at all and at the moment I'm also using this hacky setTimeout approach. What about a onReady prop of MapView which takes following object?
It's not a beauty :) but at least the component knows the amount of markers which need to be present and if the internal count is true calls the callback. Just my 2cent as I said I'm totally new to this! |
Any fix for this? |
calling a ref after a component is mounted and applying the fitToElements to the callback variable fixed the issue for me. this is something like onMapReady event but on react component |
@symmetriccurve thx for this hint. I checked it and it's not working on my side, getting error "Cannot read property 'fitToElements" of null" That's why it's only working with this hacky setTimeout. |
Not working for me either |
@ddresch Try this out : |
@symmetriccurve this is not working |
Alternative way: find the region that contains all the markers and change the map's region prop accordingly. |
Yes, this is what I ended up doing! |
@BaptisteT . Does it throw a error ? |
A patch was added that will included in 0.9.0 basically doing what @DennisMG mentioned so at least the application won't crash like it does now. fitToElements() unfortunately still doesn't work probably for the reason @igrayson mentioned. I ended up just writing fitToElements in JS and doing what @mynamespace said. |
onMapLayout = () =>
this.map.fitToElements(true);
render() {
return (
<MapView
ref={ref => this.map = ref}
onLayout={this.onMapLayout}
>
{/* stuff */}
</MapView>
);
} |
closing, very old |
I’m closing this issue because it has been inactive for a while. This probably means that it is not reproducible or it has been fixed in a newer version. If it’s an enhancement and hasn’t been taken on for so long, then it seems no one has the time to implement this. Please reopen if you still encounter this issue with the latest stable version. Thank you! |
To set the Google Map zoom level to show all the markers, I was suggested to use fitToElements but I am getting error "not included points"
Here is my code and markers have 2 points:
The text was updated successfully, but these errors were encountered: