3
3

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.

gmaps.jsで地図を表示する(googlemapsAPI keyが要求されるようになってからの対処)

Posted at

gmaps.jsを使って地図表示する際に以下のコードが例で挙げられる。

<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="utf-8">
    <title>gmapsサンプル</title>
    <style>
        @charset "utf-8";
        #map {
            height: 400px;
            background: #58B;
        }
    </style>
    <script src="http://maps.google.com/maps/api/js?sensor=true&.js"></script>
    <script src="https://rawgit.com/HPNeo/gmaps/master/gmaps.js"></script>
    <script>
        window.onload = function(){
            var map = new GMaps({
                div: "#map",
                lat: 35.710285,
                lng: 139.77714,
                zoom: 15,
            });
        };
    </script>
</head>
<body>
    <div id="map"></div>
</body>
</html>

ただ、2016年6月22日以降、googlemapsAPIが要求されるようになってしまい、
サーバーからアクセスする場合はAPI keyがないとアクセス出来ない感じになってしまっている。

そこで、こちらのページからAPI keyを取得。
https://developers.google.com/maps/documentation/javascript/get-api-key?hl=ja

その上で以下の部分を、

<script src="http://maps.google.com/maps/api/js?sensor=true&.js"></script>

以下のように変えると見事地図表示成功!

<script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY"></script>
3
3
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
3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?