我在谷歌地图上显示图标有问题。 这是我的代码:
import React, { Component } from 'react'
import { compose, withProps, withStateHandlers } from 'recompose'
import { withScriptjs, withGoogleMap, GoogleMap, Marker, InfoWindow } from 'react-google-maps'
import MapStyles from './data/MapStyles'
export const Map = compose(
withStateHandlers(() => ({
isOpen: false,
}), {
onToggleOpen: ({ isOpen }) => () => ({
isOpen: !isOpen,
})
}),
withScriptjs,
withGoogleMap
)(props => {
return (
<GoogleMap
defaultZoom={13}
defaultCenter={{ lat: 52.229676, lng: 21.012229 }}
defaultOptions={{ styles: MapStyles }}
mapTypeControl={false}
>{ props.markers.map(marker => {
console.log(marker.location);
<Marker
{...marker}
key={marker.place_id}
position={marker.location}
title={marker.title}
icon={{
url: 'icons/icon.png'
}}
onClick={props.onToggleOpen}
>
{props.isOpen &&
<InfoWindow onCloseClick={props.onToggleOpen}>
<div>Open</div>
</InfoWindow>}
</Marker>
})}
</GoogleMap>
);})
export default Map
标记的位置由console.log在控制台中显示,但它们不会显示在地图上......我不知道为什么......也许有些人知道,为什么会发生这种情况......以下是Github上此项目的链接:https://github.com/hajczek/Neighborhood---Warsaw-Cultural-Map
感谢任何提示。
答案 0 :(得分:0)
您在地图投影中错过了return
-
>{ props.markers.map(marker => {
console.log(marker.location);
<Marker
在return
<Marker
>{ props.markers.map(marker => {
console.log(marker.location);
return <Marker
codesandbox上的工作样本