Bug iOS: Map goes on a stroll when I maintain the region
Is this a bug report?
Yes.
Maintaining the state in my component works on default provider (Apple maps) but not with Google maps.
Watch this video to see the behaviour in action: https://youtu.be/yX-CuleGr-o
Have you read the Installation Instructions?
Yes
Environment
{
"react": "16.6.3",
"react-native": "0.58.3",
"react-native-maps": "^0.23.0"
}
Using Google Maps.
Steps to Reproduce
- Setup a new project with react native maps and add the google maps sdk (iOS).
- Create a component with the following code:
import React, { Component } from 'react';
import MapView, { PROVIDER_GOOGLE, Region } from 'react-native-maps';
export class Map extends Component {
constructor(props) {
super(props);
this.state = {
region: {
latitude: 52.3546274,
longitude: 4.8285839,
latitudeDelta: 0.015,
longitudeDelta: 0.0121,
},
};
}
render() {
return (
<MapView
region={this.state.region}
onRegionChangeComplete={region => this.setState({ region })}
provider={PROVIDER_GOOGLE}
style={{flex: 1}}
/>
);
}
}
Tested on the iPhone X simulator, watch as the map slowly crawls away for some reason.
Expected Behavior
No crawling at all.
Actual Behavior
https://youtu.be/yX-CuleGr-o
Reproducible Demo
https://snack.expo.io/@rwoverdijk/maps-scoot-scoot-not-good
Update: Even without the initial state this occurs. The only thing I can imagine going wrong here, is a floating point decimal positions mismatch. That being said, I don't know. 😄
@RWOverdijk - I am getting this but it's slightly more vigorous and in the other direction. It only seems to be on a physical device but not the emulator. Were you able to solve this?
My onRegionChangeComplete event on the MapView was causing my issue (like yourself it seems), but you (and I) are using the event like most examples online. I'm wondering what the device is executing that the simulator isn't.
Any updates? I am facing the same issue
So far I managed it by setting provider={MapKit}. But whenever I try to use google map then I got the same error again
I found out if we use only 'this' instead of using state to set value then the problem is gone! Does anyone have any explanation? @ciawalsh @RWOverdijk
Because state triggers rerenders. Using a property is a bad idea from a react perspective.
I am having the same issue on my simulator and iphone 6s when I use google maps... Any help please?
@gtatyous I did it by updating location value using "this"
@aniksharif thats not a good solution!!! I fixed mine by disabling the onRegionChange and onRegionChangeComplete methods from my mapview... but soon enough I am going need to use these methods and I cannot just fix this issue just by passing .setState() function. Is there another way to get around this without using "this"?
What I did was just let go control of the location. I let the map rule everything. If I need to go somewhere specific I call animateCamera once, and then forget about it. It's not perfect but it works.
Facing the exact problem. Is there any workaround for this?
@gtatyous I think you got me wrong I didn't use .setState() function. I did this.
onRegionChangeComplete={region => this.region=region}
I experienced the same issue. For some reason if the map is not full screen this issue doesn't occur on me. I added a footer and a header on my screen and the issue is not happening anymore.
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.