Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Re-center map if new center property value equals to previous one, but map was re-positioned manually#1100

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
undeletable wants to merge1 commit intogoogle-map-react:master
base:master
Choose a base branch
Loading
fromundeletable:center-after-move

Conversation

undeletable
Copy link

@undeletableundeletable commentedMar 26, 2022
edited
Loading

Related to#546
Assume the following code:

import React, {Fragment, useEffect, useState} from 'react';import GoogleMapReact from 'google-map-react';const Map = () => {  const [center, setCenter] = useState();  useEffect(() => {    window.navigator.geolocation.getCurrentPosition(position => {      setCenter({        lat: position.coords.latitude,        lng: position.coords.longitude      });    });  }, []);  return <Fragment>    <GoogleMapReact      bootstrapURLKeys={{ key: 'my_api_key' }}      center={center}      yesIWantToUseGoogleMapApiInternals    />  <button    onClick={() => window.navigator.geolocation.getCurrentPosition(position => {      setCenter({        lat: position.coords.latitude,        lng: position.coords.longitude      });    })}  >    Locate Me  </button>  </Fragment>;};

Execute the following steps:

  1. Click 'Locate Me' button - map would be centered to the detected location.
  2. Move the map.
  3. Click 'Locate Me' - map would not be centered, even thougn center prop receives the expected value.

center prop value is not changed (on steps 1 and 3 coordinates are the same), but at the same timecenter prop value is different from actual center. Such a behavior of component might be confusing. IMHO, when deciding whether to re-center map programmatically, it makes sense to compare center value with current actual center.

harishowt reacted with thumbs up emoji
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

1 participant
@undeletable

[8]ページ先頭

©2009-2025 Movatter.jp