LoginSignup
4
7

More than 5 years have passed since last update.

Google Maps API warning: SensorNotRequired

Last updated at Posted at 2016-01-10

はじめに

Google Maps JavaScript APIを使っていたら、なんかエラーが出ていたのでメモ。
Google Maps API warning: SensorNotRequired ってエラーの対処法。

GoogleMaps表示コード

Google Maps JavaScript APIを使うとき、下記スクリプトを書くと思います。

index.html
<script src="https://maps.googleapis.com/maps/api/js?sensor=(false or true)"></script>

それで、実際にGoogleMapを表示するサンプルコードがこれ。(何でもいいのですが一応)

index.html
<!DOCTYPE html>
<html>
<head>
    <title>Simple Map</title>
    <meta name="viewport" content="initial-scale=1.0">
    <meta charset="utf-8">
    <style>
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
        }
        #map {
            height: 500px;
            width: 50%;
        }
    </style>
</head>
<body>
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script>

    function initMap() {
        var myLatLng = {lat: 35.658581, lng: 139.745433};

        var map = new google.maps.Map(document.getElementById('map'), {
            zoom: 14,
            center: myLatLng
        });

        var marker = new google.maps.Marker({
            position: myLatLng,
            map: map,
        });
    }
    initMap();

</script>
</body>
</html>

そして、実際にマップを表示させてみると、コンソールログになんだかエラーが出てるではありませんか。

Google Maps API warning: SensorNotRequired

Google Maps API warning: SensorNotRequired: https://developers.google.com/maps/documentation/javascript/error-messages

ほー。

色々調べたら、公式ドキュメントに載っているではありませんか!!!

The sensor parameter is no longer required for the Google Maps JavaScript API. It won't prevent the Google Maps JavaScript API from working correctly, but we recommend that you remove the sensor parameter from the script element.

パラメータでつけていた sensor=(false or true) が必要なくなっているみたいです。

ということで、これを

index.html
<script src="https://maps.googleapis.com/maps/api/js?sensor=(false or true)"></script>

こうすれば

index.html
<script src="https://maps.googleapis.com/maps/api/js"></script>

エラーが消えます!

Google Maps JavaScript APIの使い方を紹介している記事は大体 sensor=(false or true)を付けてるのが多いですから引っ掛かりますね。いや、ドキュメント読めよとか言わないで

ということで、一件落着!!!!

おわりに

先日記事にしました Google Maps API の基本的な使い方 ではエラーが出ることは無かったのですが、違う案件でGoogle Maps JavaScript APIを書いていたらなぜか sensor=(false or true) を付けてました。。。

人間、すぐ忘れる生き物ですから。気をつけます。。。

4
7
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
4
7