【问题标题】:Google Maps are not showing with domainname.comGoogle 地图未显示 domainname.com
【发布时间】:2016-11-22 08:09:01
【问题描述】:

JavaScript:

<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 地图 API 错误:RefererNotAllowedMapError https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map-error 您要授权的站点网址:http://comprettainsurance.com/contactus"

如果我这样打开我的网站。

http://www.mysiste.com/contactus

地图运行良好。

我的凭据页面,我在其中添加这样的域。

那么为什么它不显示没有www 的地图?

【问题讨论】:

    标签: javascript google-maps google-chrome firefox google-maps-api-3


    【解决方案1】:

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

    您需要添加额外的referrer line:

    comprettainsurance.com/*
    

    【讨论】:

    • 我是否也应该在列表中添加此推荐人。 *.comprettainsurance.com/contactus* ?
    • 如果你想让www.comprettainsurance.com/contactus 工作,你也需要那个。
    • 它不是通用的吗?我的意思是我只添加一行,应该适用于网站的所有页面?
    • 对不起,我看错了你的评论。如果你想让http://www.comprettainsurance.com/contactus 工作,你还需要*.comprettainsurance.com/*(或www.comprettainsurance.com/*)。
    • *.comprettainsurance.com/* 我需要这条线来工作www 和网站的所有页面,我需要这条线comprettainsurance.com/* 在没有www 的情况下工作。对于所有没有www 的页面,我理解你吗?请
    【解决方案2】:

    像这样使用简单,这对我来说无处不在

    <script type="text/javascript" src="http://maps.google.com/maps/api/js?key=key&libraries=places,drawing,geometry"></script>
    

    当您使用 defer 时,脚本将在文档关闭时加载 - 内容已加载。此外,外部延迟脚本将在内联延迟脚本之后进行解析。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-07-15
      • 2019-01-05
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多