如何使用 react-google-maps 在街景模式下初始化地图
How do I initialize a map in street view mode using react-google-maps
我已经实现了默认的 react-google-map 组件,它可以正确显示地图。但是,有没有办法将其初始化为给定坐标的街景?
原代码我想修改如下:
const Map = compose(
withProps({
containerElement: <div style={{ height: `100%` }} />,
mapElement: <div style={{ height: `100%` }} />
}),
withGoogleMap
)(props => (
<GoogleMap
defaultZoom={18}
defaultCenter={{ lat: props.coord.lat, lng: props.coord.lng }}
>
{true && (
<Marker position={{ lat: props.coord.lat, lng: props.coord.lng }} />
)}
</GoogleMap>
));
我已经共享了 streetViewPanorama 的 codesandbox。但是你需要在映射 url 中添加你的 API 键。
代码和框:https://codesandbox.io/s/147kvk67zj
有任何问题欢迎随时提问。
<LoadScript googleMapsApiKey={api}>
<GoogleMap
mapContainerStyle={{width: "100%", height: "100%"}}
center={center}
zoom={10}
options={options}
>
<StreetViewPanorama position={center} visible={true}/>
</GoogleMap>
</LoadScript>
我已经实现了默认的 react-google-map 组件,它可以正确显示地图。但是,有没有办法将其初始化为给定坐标的街景?
原代码我想修改如下:
const Map = compose(
withProps({
containerElement: <div style={{ height: `100%` }} />,
mapElement: <div style={{ height: `100%` }} />
}),
withGoogleMap
)(props => (
<GoogleMap
defaultZoom={18}
defaultCenter={{ lat: props.coord.lat, lng: props.coord.lng }}
>
{true && (
<Marker position={{ lat: props.coord.lat, lng: props.coord.lng }} />
)}
</GoogleMap>
));
我已经共享了 streetViewPanorama 的 codesandbox。但是你需要在映射 url 中添加你的 API 键。 代码和框:https://codesandbox.io/s/147kvk67zj
有任何问题欢迎随时提问。
<LoadScript googleMapsApiKey={api}>
<GoogleMap
mapContainerStyle={{width: "100%", height: "100%"}}
center={center}
zoom={10}
options={options}
>
<StreetViewPanorama position={center} visible={true}/>
</GoogleMap>
</LoadScript>