0

的JavaScript:谷歌地圖不與domainname.com顯示

<script async defer src="https://maps.googleapis.com/maps/api/js?key=mykey"type="text/javascript"></script> 

JavaScript函數:

<script type="text/javascript"> 
    var geocoder; 
    var map; 
    var latlng; 

    function codeAddress(address) { 
    geocoder = new google.maps.Geocoder(); 
    if (geocoder) { 
     geocoder.geocode({ 'address': address}, function(results, status) { 
     if (status == google.maps.GeocoderStatus.OK) { 
      latlng=results[0].geometry.location; 
      latlng = new google.maps.LatLng(latlng); 
      var myOptions = { 
       zoom: 13, 
       center: latlng, 
       mapTypeId: google.maps.MapTypeId.ROADMAP 
      }; 
      var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 
        map.setCenter(results[0].geometry.location); 
        var marker = new google.maps.Marker({ 
         map: map, 
         position: results[0].geometry.location 
       }); 

     } else { 
      alert("Geocode was not successful for the following reason: " + status); 
     } 
     }); 
    } 
    } 
</script> 

我讀下面的問題,但我的問題沒有得到解決。

Google Maps JavaScript API RefererNotAllowedMapError

Google maps API referrer not allowed

Google Maps API error: Google Maps API error: RefererNotAllowedMapError

的問題是,當我打開我的網站,像這樣的。

http://mysiste.com/contactus 

它沒有顯示地圖和表示跟隨誤差。

Google Maps API error: RefererNotAllowedMapError https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error Your site URL to be authorized: http://comprettainsurance.com/contactus "

而如果我打開我的網站是這樣的。

http://www.mysiste.com/contactus 

地圖工作完美。

My Credential Page我在這裏添加域名。

enter image description here

那麼,爲什麼它沒有顯示不www地圖?

回答

3

*.comprettainsurance.com/*不匹配http://comprettainsurance.com/contactus(它匹配comprettainsurance.com的任何子域,但不匹配域本身)。

您需要添加額外引用行:

comprettainsurance.com/* 
+0

我應該在列表中添加這個推薦人。 '* .comprettainsurance.com/contactus *'? –

+0

如果你想'www.comprettainsurance.com/contactus'工作,你也需要一個。 – geocodezip

+0

它不是通用的我的意思是我只是添加一行,並應在網站的所有頁面上工作? –

2

這樣這樣使用簡單工作對我來說處處

<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=key&libraries=places,drawing,geometry"></script> 
當您使用延遲在對文檔進行閉環的內容已經被加載腳本將被載入

。此外,內聯defferred腳本後將解析外部deferred腳本。

+0

OK @Adi感謝,現在我更新我的問題。 –