反应谷歌地图标记没有生效

时间:2018-01-03 02:15:32

标签: reactjs google-maps redux react-google-maps

我想让地图以defaultMarker为中心。但是,当地图完成加载时,视图略高于默认标记。我必须向下滚动到中间才能看到defaultMarker。 知道如何在加载地图时将视图居中吗?我正在使用React,redux和react-google-maps。

import React, {Component} from 'react';
import {withGoogleMap, GoogleMap, Marker} from "react-google-maps";
import {connect} from 'react-redux';

class VenuesMap extends Component {

  render() {

        let markers;
        if (this.props.venues !== null) {
            markers = this.props.venues.map((venue, i) => {
                return (
                    <Marker
                        key={i}
                        position={{ lat: venue.location.lat, lng: venue.location.lng}}
                    />
                )
            })
        } else {
            markers = <Marker position={{ lat: 40.7589, lng:-73.9851}}/>
        }
const MapWithAMarker = withGoogleMap(props =>
  <GoogleMap
        defaultCenter={{ lat: 40.7589, lng: -73.9851 }}
        center={{ lat: 40.7589, lng: -73.9851 }}
        zoom={15}
  >
    {markers}
  </GoogleMap>
);
        const googleMap =   <MapWithAMarker
            containerElement={<div style={{
                                height: `410vh`
            }} />}
            mapElement={<div style={{ height: `410vh`
             }} />}
        />
    return (
            <div>
                {googleMap}
            </div>
        )
  }
}

const stateToProps = (state) => {
  return {venues: state.venue.venues}
}

export default connect(stateToProps)(VenuesMap)

When the map starts it is above the default Marker I have to scroll down

1 个答案:

答案 0 :(得分:0)

最大窗口高度为100vh

只需尝试height: 100vh或更少。