React-google-maps: defaultCenter and defaultZoom not working

Created on 4 Aug 2016  路  6Comments  路  Source: tomchentw/react-google-maps

Does anyone know how to access the map object to set the center and the zoom? This will need to happen after the map renders. Adding the values to the defaultZoom and/or defaultCenter in the render doesn't affect the view.

Most helpful comment

Have you tried using defaultOptions props ?

That is where you can pass map styles, an object like:

{
  minZoom: 3,
  fullscreenControl: false,
  // zoomControl: false,
  streetViewControl: false,
  scaleControl: true,
  mapTypeControl: true,
  mapTypeControlOptions,
  styles: [...administrative, ...landscape, ...poi, ...road, ...transit, ...water]
}

where administrative, landscape, etc. are objects with featureType, elementType, stylers properties

You can probably pass a streetViewControl: true

All 6 comments

You have to use controlled props (center, zoom), defaultCenter and defaultZoom are uncontrolled props.

One solution that's working (v4.11.0) for me is passing (center, zoom) controlled props only when they are defined:
<GoogleMap ref='map' {...this.optionalProps} ...
and using shouldComponentUpdate to control map re-renders

Does anyone knows how to remove map controls?
For example I don't want to have the streetViewControl, I am setting the property to the map like:
<GoogleMap zoom={zoom} center={center} streetViewControl={false}

but it doesn't work, still shows the man icon for streetview..
any thoughts @tomchentw ?

Thanks!

Have you tried using defaultOptions props ?

That is where you can pass map styles, an object like:

{
  minZoom: 3,
  fullscreenControl: false,
  // zoomControl: false,
  streetViewControl: false,
  scaleControl: true,
  mapTypeControl: true,
  mapTypeControlOptions,
  styles: [...administrative, ...landscape, ...poi, ...road, ...transit, ...water]
}

where administrative, landscape, etc. are objects with featureType, elementType, stylers properties

You can probably pass a streetViewControl: true

@amangeot thanks! it worked for me.

Thanks @amangeot for answering!

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/

@amangeot's solution works. Or you can use the options prop

Was this page helpful?
0 / 5 - 0 ratings

Related issues

0x1bitcrack3r picture 0x1bitcrack3r  路  3Comments

tahir-masood1 picture tahir-masood1  路  4Comments

MrSaints picture MrSaints  路  3Comments

EvHaus picture EvHaus  路  3Comments

johnantoni picture johnantoni  路  3Comments