【发布时间】:2018-11-02 04:16:46
【问题描述】:
我在谷歌地图上显示图标时遇到问题。 这是我的代码:
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
感谢任何提示。
【问题讨论】:
-
MapStyles下的内容 -
这是带有地图样式的文件...
标签: javascript reactjs google-maps react-google-maps