Skip to content
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

How to make the view always visible with the 2 points? #27

Closed
djalmaaraujo opened this issue Mar 12, 2018 · 3 comments
Closed

How to make the view always visible with the 2 points? #27

djalmaaraujo opened this issue Mar 12, 2018 · 3 comments

Comments

@djalmaaraujo
Copy link

Example. I am rendering 2 points.. but I want the zoom to always show the 2 points. So I need to adjust. I am not sure what calc is that or if it's too complicate.

This is the map:

image

What would be the calc to always show the 2 points? :}

@bramus
Copy link
Owner

bramus commented Mar 12, 2018

Yes, you can use the onReady callback for this, in combination with the fitToCoordinates method of the <MapView /> component:

      <MapView
        initialRegion={…}
        ref={c => this.mapView = c}
      >
          <MapViewDirections
            origin={…}
            destination={…}
            apikey={GOOGLE_MAPS_APIKEY}
            onReady={(result) => {
              this.mapView.fitToCoordinates(result.coordinates, {
                edgePadding: {
                  right: (width / 20),
                  bottom: (height / 20),
                  left: (width / 20),
                  top: (height / 20),
                }
              });
            }}
          />
      </MapView>

Note that a reference to the <MapView /> component was made (this.mapView) in order to make things work.

@bramus bramus closed this as completed Mar 12, 2018
@djalmaaraujo
Copy link
Author

Thanks @bramus, you are super fast.

@thorizer
Copy link

thorizer commented Dec 7, 2021

@bramus how to use this in a functional component? ( this.mapView instance )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants