react-native-maps icon indicating copy to clipboard operation
react-native-maps copied to clipboard

Bug iOS: Map goes on a stroll when I maintain the region

Open RWOverdijk opened this issue 7 years ago • 14 comments

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

  1. Setup a new project with react native maps and add the google maps sdk (iOS).
  2. 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

RWOverdijk avatar Feb 07 '19 15:02 RWOverdijk

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 avatar Feb 11 '19 10:02 RWOverdijk

@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.

ciawalsh avatar Feb 21 '19 15:02 ciawalsh

Any updates? I am facing the same issue

aniksharif avatar Mar 06 '19 14:03 aniksharif

So far I managed it by setting provider={MapKit}. But whenever I try to use google map then I got the same error again

aniksharif avatar Mar 06 '19 14:03 aniksharif

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

aniksharif avatar Mar 13 '19 06:03 aniksharif

Because state triggers rerenders. Using a property is a bad idea from a react perspective.

RWOverdijk avatar Mar 13 '19 15:03 RWOverdijk

I am having the same issue on my simulator and iphone 6s when I use google maps... Any help please?

gtatyous avatar Mar 14 '19 00:03 gtatyous

@gtatyous I did it by updating location value using "this"

aniksharif avatar Mar 14 '19 09:03 aniksharif

@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"?

gtatyous avatar Mar 20 '19 20:03 gtatyous

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.

RWOverdijk avatar Mar 21 '19 08:03 RWOverdijk

Facing the exact problem. Is there any workaround for this?

Balasnest avatar Mar 21 '19 13:03 Balasnest

@gtatyous I think you got me wrong I didn't use .setState() function. I did this. onRegionChangeComplete={region => this.region=region}

aniksharif avatar Mar 21 '19 14:03 aniksharif

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.

timgarciaa avatar Jan 09 '20 08:01 timgarciaa

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.

stale[bot] avatar Oct 02 '20 21:10 stale[bot]