reactjs - 标记不适用于 google-map-react

标签 reactjs api google-maps markers

我正在使用“google-map-react”库,我已经尝试了所有但标记没有出现。 我以多种方式将坐标传递给标记,但都没有奏效。 这是我的代码和存储库:

https://github.com/jorginyu/ubica

import React, { Component } from 'react';
import GoogleMapReact from 'google-map-react';

const API_KEY = 'WTFULOOKINAT';

const contacts = [
  { name: 'Spiderman', lat: 41.529616, lng: 2.434130 },
  { name: 'Iron Man', lat: 41.528103, lng: 2.433834 },
  { name: 'Hulk', lat: 41.530192, lng: 2.422994 }
];

const MarkersC = (text ) => <div className="contact">{text}</div>;

export default class MapComponent extends Component {
  constructor(props) {
    super(props);
    this.state = {
      center: {
        lat: 41.528452,
        lng: 2.434195
      },
      zoom: 18
    }
  }


  render() {
    return (
      // Important! Always set the container height explicitly
      <div className="mt-5" style={{ height: '80vh', width: '100%' }}>
        <GoogleMapReact
          bootstrapURLKeys={{ key: API_KEY }}
          defaultCenter={this.state.center}
          defaultZoom={this.state.zoom}
        >
            {contacts.map((contact,i) => {
            <MarkersC  position={{lat: contact.lat, lng: contact.lng}} text={contact.name} key={i} />
          })}

        </GoogleMapReact>
      </div>
    );
  }
}

我能做什么?感谢您的宝贵时间:)

最佳答案

存在格式问题。我删除了空格:

然后:

          {
            contacts.map((contact, i) => 
              <MarkersC lat={contact.lat} lng={contact.lng} text={contact.name} key={i} />
            )
          }

现在:

          {
            contacts.map((contact, i) => <MarkersC lat={contact.lat} lng={contact.lng} text={contact.name} key={i} /> )
          }

关于reactjs - 标记不适用于 google-map-react,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60147126/

相关文章:

javascript - 我可以在nodejs中的javascript路径中传递变量吗?我正在使用查询方法

azure - 对 Azure Maps 搜索中的结果进行排序

javascript - 如何使用 javascript 结合地理定位和多个标记?

reactjs - React + springboot csrf

javascript - Reactjs create-react-app my-app 后端集成

javascript - Webback list 文件未编译为 es5

javascript - 如何在 ReactJS 中单击时仅切换元素集合中的一个元素?

xml - CSV、JSON 和 XML 对于 REST API 的相对优点是什么?

android - Google map 上的蓝色闪光灯 (Arc)

javascript - 如何在谷歌地图中添加多个标记