react中使用google map展示地图

1. 安装插件 google-maps-react

npm install google-maps-react --save

2. 使用

import React, { Component } from "react";
import { Map, GoogleApiWrapper, Marker } from "google-maps-react";

class MapContainer extends Component {
  render() {
    const mapStyles = {
      width: "100%",
      height: "400px",
    };

    return (
      <Map
        google={this.props.google}
        zoom={14}
        style={mapStyles}
        initialCenter={{
          lat: 22.30080, // 纬度
          lng: 114.17868, // 经度
        }}
      >
        <Marker position={{ lat: 22.30080, lng: 114.17868 }} />
      </Map>
    );
  }
}

export const GoogleMap = GoogleApiWrapper({
  apiKey: process.env.REACT_APP_GOOLE_MAP_API,
  language: 'CN',
})(MapContainer);

相关推荐

  1. react使用google map展示地图

    2024-03-27 04:16:03       35 阅读
  2. react使用腾讯地图

    2024-03-27 04:16:03       48 阅读
  3. React】前端React 代码预览展示excel文件

    2024-03-27 04:16:03       48 阅读
  4. React使用WebRTC

    2024-03-27 04:16:03       60 阅读
  5. React 使用 TS

    2024-03-27 04:16:03       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-27 04:16:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-27 04:16:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-27 04:16:03       87 阅读
  4. Python语言-面向对象

    2024-03-27 04:16:03       96 阅读

热门阅读

  1. 五.指针和引用的异同点

    2024-03-27 04:16:03       40 阅读
  2. OD C卷 - 贪心的歌手

    2024-03-27 04:16:03       40 阅读
  3. 【Kubernetes】在 CentOS 7 上搭建 Kubernetes

    2024-03-27 04:16:03       42 阅读
  4. jsp学习

    jsp学习

    2024-03-27 04:16:03      40 阅读
  5. 线程: park & unpark(2)

    2024-03-27 04:16:03       39 阅读
  6. 基于画布canvas进行图片压缩

    2024-03-27 04:16:03       42 阅读
  7. 给wordpress添加自定义字段的分类筛选功能

    2024-03-27 04:16:03       42 阅读
  8. 【C++】每日一题,238 除自身以外数组的乘积

    2024-03-27 04:16:03       36 阅读
  9. [蓝桥杯 2019 省 B] 特别数的和

    2024-03-27 04:16:03       37 阅读