13
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ReactでGoogleMapsを使う

13
Last updated at Posted at 2018-02-07

はじめに

ReactでGoogleMapsを使う際に、Mapをコンポーネントとして実装するならこれが一番だと思います。
生のJSのように導入しようとしたら、うまくいかなかったのでメモ。

環境構築

1.モジュールをインストールする。
 npm install --save react-google-map react-google-maps-loader
2. APIキーの取得
 ここからAPIキーの取得ができます。

使用例

map.jsx
import React from "react"
import ReactGoogleMapLoader from "react-google-maps-loader"
import ReactGoogleMap from "react-google-map"

const bnCoord = {
  lat: 44.597923,
  lng: 0.873799,
}

const Map = () => (
    <ReactGoogleMapLoader
      params={{
        key: "取得したキーをここに入力する",
      }}
      style={{height: "100%"}}
      render={googleMaps => {
        return (
          googleMaps && (
            <ReactGoogleMap
              googleMaps={googleMaps}
              coordinates={[
                {
                  title: "Bosc Nègre",
                  position: bnCoord,
                },
              ]}
              center={bnCoord}
              zoom={8}
            />
          )
        )
      }}
    />
)

export default Map
13
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
13
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?