6
8

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 3 years have passed since last update.

完成形
image.png

Google Map React

でも紹介されているGoogle Map React。いくつか過去記事がある。

今回使うのは以下。

npm install --save google-map-react

サンプル

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

const AnyReactComponent = ({ text }) => <div>{text}</div>;

class SimpleMap extends Component {
  static defaultProps = {
    center: {
      lat: 35.66, // 緯度経度
      lng: 139.74
    },
    zoom: 15
  };

  render() {
    return (
      // Important! Always set the container height explicitly
      <div style={{ height: '100vh', width: '100%' }}>
        <GoogleMapReact
          bootstrapURLKeys={{ key:'{API キーをここに}' }}
          defaultCenter={this.props.center}
          defaultZoom={this.props.zoom}
        >
          <AnyReactComponent
            lat={35.667345081692176}
            lng={139.7401442420512}
            text="アークヒルズはここ"
          />
        </GoogleMapReact>
      </div>
    );
  }
}

export default SimpleMap;

トラブルシューティング

依存関係の解決

npm install --save --legacy-peer-deps google-map-react

APIキー

このページでは Google マップが正しく読み込まれませんでした。JavaScript コンソールで技術情報をご確認ください。

「Google Maps JavaScript API」で「有効にする」ことで、このエラーを抑止して、利用できるようになります。

You must enable Billing on the Google Cloud Project at https://console.cloud.google.com/project/_/billing/enable
Learn more at https://developers.google.com/maps/gmp-get-started

Zoomとは

Zoom は 0 to 18。

ということで超簡単にできた!という以上メモ書きだが、なにがしか参考になればさいわいです。

6
8
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
6
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?