2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Googleマップのスター(保存済みの場所)をJavaScriptで高速一括削除する方法と「座標ピン」の罠

2
Posted at

はじめに

Googleマップに登録した大量のスターを一括削除する公式機能はありません。PCのデベロッパーツール(コンソール)を使ってJavaScriptを実行すれば高速で削除できますが、一部のピンには「罠」があります。その解決策をまとめました。

1. 通常のスポット(店舗や施設)を一括削除するコード

お店や駅など、名前がある場所のスターは以下のコードをコンソールに貼り付けるだけで、上から順に自動で削除できます。

(function() {
    const totalDeleteCount = 50; // 消したい件数を指定
    let deleteCounter = 0;

    function deleteTopItem() {
        if (deleteCounter >= totalDeleteCount) {
            console.log(`完了しました。`);
            return;
        }

        // 画面内のボタンから「保存」や「削除」に関連する要素を抽出
        const buttons = Array.from(document.querySelectorAll('button')).filter(btn => {
            const label = btn.getAttribute('aria-label') || '';
            return label.includes('保存') || label.includes('消去') || label.includes('削除') || btn.querySelector('svg');
        });

        if (buttons.length === 0) {
            console.log("ボタンが見つかりません。");
            return;
        }

        try {
            buttons[0].click(); // 常に一番上のアイテムを削除
            deleteCounter++;
            setTimeout(deleteTopItem, 2000); // 2秒間隔で実行
        } catch (e) {
            setTimeout(deleteTopItem, 3000);
        }
    }
    deleteTopItem();
})();

2. 【注意】数字の「緯度・経度」で登録したピンは消えない?

(35.123456, 138.123456) のような緯度・経度の数字だけで登録されたピンは、上記のスクリプトを実行すると消えていき、画面上に「削除しました」と通知が出ますが、削除はできておらず、リロードすると復活します。

Screenshot 2026-05-20 at 13.58.29.png

原因

Googleマップの仕様上、緯度・経度ピンは「一度その場所をクリックしてアクティブ(選択状態)にする」「詳細メニューからスターを外す」という手順を踏まないと、サーバー側で削除が確定しない仕組みになっているためです。

Screenshot 2026-05-20 at 13.58.34.png

3. 緯度・経度ピンを確実に消す手順

数字の座標ピンが残ってしまった場合は、以下の「人間と同じ手動ステップ」で消していくのが最も確実です。

  1. リスト内のアイテムのブックマークアイコンをクリックしてメニューを開く
  2. メニュー内の「スター付き」のチェックを外す

まとめ

  • 普通のスポットはJavaScriptの自動クリックで一瞬で片付く
  • 緯度・経度のピンはGoogle側の通信の仕様上、空振りしやすいので個別にメニューからチェックを外す必要がある

自動化を試みて「なぜかスターが減らない」と悩んでいる方は、自分のリストに座標ピンが混ざっていないか確認してみてください。

2
1
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
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?