質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

Q&A

0回答

894閲覧

rails Googlemap 表示できない。

naru_asa

総合スコア1

Google API

Googleは多種多様なAPIを提供していて、その多くはウェブ開発者向けのAPIです。それらのAPIは消費者に人気なGoogleのサービス(Google Maps, Google Earth, AdSense, Adwords, Google Apps,YouTube等)に基づいています。

Ruby on Rails

Ruby on Railsは、オープンソースのWebアプリケーションフレームワークです。「同じことを繰り返さない」というRailsの基本理念のもと、他のフレームワークより少ないコードで簡単に開発できるよう設計されています。

Google マップ

Google Mapは、Google社がオンラインで提供している地図・ローカル検索サービスです。GIS(Geographic Information System:地理情報システム)の中の「WebGIS」に該当します。地図・航空写真・地形の表示方式があり、それぞれユーザーが縮尺を調整して表示させることができます。地域の情報サービスを検索する機能やルート検索の機能も搭載されています。

0グッド

0クリップ

投稿2021/10/28 12:57

編集2021/10/28 14:15

###前提・実現したいこと
画像投稿サイトでGooglemapを表示させたいが、エラーが出てしまい解決できない。
他サイトなどを参考に施行錯誤したが、APIキーやキーの書き方自体に問題がなさそうです。
###発生している問題・エラーメッセージ
「このページでは Google マップが正しく読み込まれませんでした。
このウェブサイトの所有者ですか?」
この表記がマップ上に表示される。
「Google Maps JavaScript API warning: NoApiKeys」も出ている。
###該当のソースコード

html

1<div class="map" style="padding-top:25px" > 2 <p><%= @post.address %></p> 3 <div id="map" ></div> 4 5 <style> 6 #map{ 7 height: 400px; 8 width: 555px; 9 } 10 </style> 11 12 <script type="text/javascript"> 13 function initMap() { 14 var test ={lat: <%= @post.latitude %>, lng: <%= @post.longitude %>}; 15 var map = new google.maps.Map(document.getElementById('map'), { 16 zoom: 15, 17 center: test 18 }); 19 var transitLayer = new google.maps.TransitLayer(); 20 transitLayer.setMap(map); 21 22 var contentString = '住所:<%= @post.address %>'; 23 var infowindow = new google.maps.InfoWindow({ 24 content: contentString 25 }); 26 27 var marker = new google.maps.Marker({ 28 position:test, 29 map: map, 30 title: contentString 31 }); 32 33 marker.addListener('click', function() { 34 infowindow.open(map, marker); 35 }); 36 } 37 </script> 38 39 <script src="https://maps.googleapis.com/maps/api/js?key=<%= ENV['GOOGLE_MAP_API_KEY'] %>&callback=initMap" async defer></script> 40 41 </div> 42 43 <div class="comment shadow p-3 mb-3" style="padding-top:40px"> 44 <%= form_with(model:[@post, @post_comment], local: true) do |f| %> 45 <h5>コメント投稿</h5> 46 <div class="row col align-self-center"> 47 <div class="comment-text"> 48 <%= f.text_area :comment, :size=>"40x2" ,placeholder: "ここに入力!" %> 49 </div> 50 <div class="comment-submit align-self-center" style="padding-left:25px"> 51 <%= f.submit "投稿する", class: "btn btn-success" %> 52 </div> 53 </div> 54 <% end %> 55 </div>
.env GOOGLE_MAP_KEY='-KEY-'
Geocoder.configure( # Geocoding options # timeout: 3, # geocoding service timeout (secs) lookup: :google, # name of geocoding service (symbol) # ip_lookup: :ipinfo_io, # name of IP address geocoding service (symbol) # language: :en, # ISO-639 language code use_https: true, # use HTTPS for lookup requests? (if supported) # http_proxy: nil, # HTTP proxy server (user:pass@host:port) # https_proxy: nil, # HTTPS proxy server (user:pass@host:port) api_key: ENV['GOOGLE_MAP_API_KEY'] # API key for geocoding service # cache: nil, # cache object (must respond to #[], #[]=, and #del) # cache_prefix: 'geocoder:', # prefix (string) to use for all cache keys # Exceptions that should not be rescued by default # (if you want to implement custom error handling); # supports SocketError and Timeout::Error # always_raise: [], # Calculation options # units: :mi, # :km for kilometers or :mi for miles # distances: :linear # :spherical or :linear )

・請求アカウントもプロジェクトに紐づいていた。
・APIキーも問題無かった。
・怪しいのは、リファラー設定で
https://~~~~.amazonaws.com/*
https://~~~~.amazonaws.com/
上記を登録している。

環境
・ruby '2.6.3'
・rails '5.2.6'
・cloud9

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問