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
它不显示 map 并显示以下错误。
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
map 运行良好。
我的凭据页面,我在其中添加了这样的域。
那么为什么它不显示没有 www
的 map ?
最佳答案
*.comprettainsurance.com/*
与 http://comprettainsurance.com/contactus
不匹配(它与 comprettainsurance.com 的任何子域匹配,但不与域匹配)本身)。
您需要添加额外的引荐来源行:
comprettainsurance.com/*
关于javascript - Google map 未显示 domainname.com,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38458379/