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

Responsive container #323

Closed
brandonmp opened this issue Aug 9, 2016 · 10 comments
Closed

Responsive container #323

brandonmp opened this issue Aug 9, 2016 · 10 comments

Comments

@brandonmp
Copy link

From reading through the issues in this project, it looks like the container has to have a height/width set in px.

Has anyone figured out how to circumvent that and make this component responsive? I can render it fine w/ fixed height/width, but that's not really tenable for the long-term.

@brandonmp
Copy link
Author

brandonmp commented Aug 9, 2016

classic: I posted an issue/question, then immediately found a solution

These settings seem to work:

Wrapping the entire GoogleMapLoader component:

<div 
 style={{ height: 350, 
width: '100%', 
display: 'flex', 
flexFlow: 'row nowrap', 
justifyContent: 'center', 
padding: 0 }}
>

Then, the containerElement prop:

<div
style={{
  width: "100%"
  marginLeft: 0
}}
            />

@brandonmp
Copy link
Author

Going to leave open for now since a lot of issues in this project instruct users to give dimensions in absolute pixel values. Would be interested to hear from a dev on the project re: best practices for responsive layout of this component

@mattmcdonald39
Copy link

I set the containerElement to a div with 100% width and height. Then wrapped the GoogleMapLoader in a Div and gave it a height: 100vh. This may not work for everyone but so far its worked for me.

@tomchentw
Copy link
Owner

I don't have a good solution either. The only thing I knew is Google Maps API requires the div to have certain dimension instead of leaving it auto.

@tomchentw
Copy link
Owner

Also, 6.0.0 is released on npm beta tag now. We also have a new demo page. Feel free to try it:
https://tomchentw.github.io/react-google-maps/

@o-aloqaily
Copy link

I managed to solve this problem by doing the following

const mapHeight = window.innerHeight
then in the style object of the map I have set the height to height: ${mapHeight}px

@roberthchapman
Copy link

Yes the key is putting the px at the end.

For me, with recompose, the props were:

withProps( props => ({
googleMapURL: https://maps.googleapis.com/maps/api/js?key=${googleApiKey}&libraries=places,
loadingElement: <div style={{ height: ${window.innerHeight - 300}px, width:100% }} />,
containerElement: <div style={{ height: ${window.innerHeight - 300}px, width:100% }} />,
mapElement: <div style={{ height: ${window.innerHeight - 300}px, width:100% }} />,
center: props.center,
ref: React.createRef()
})),

@devenovil
Copy link

classic: I posted an issue/question, then immediately found a solution

These settings seem to work:

Wrapping the entire GoogleMapLoader component:

<div 
 style={{ height: 350, 
width: '100%', 
display: 'flex', 
flexFlow: 'row nowrap', 
justifyContent: 'center', 
padding: 0 }}
>

Then, the containerElement prop:

<div
style={{
  width: "100%"
  marginLeft: 0
}}
            />

Great job @brandonmp, it's work like a charm for me!! Thanks!

@Jarrettgohh
Copy link

Thank you so much @devenovil ! It works well!

@miljkovicjovan
Copy link

Can someone point me to a direction for why is a pixel width and height needed and why percentages can't be used?

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

8 participants