0

JavaScript:

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

JavaScript Function:

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

I reads following questions but my problem is not solved.

Google Maps JavaScript API RefererNotAllowedMapError

Google maps API referrer not allowed

Google Maps API error: Google Maps API error: RefererNotAllowedMapError

The problem is , when i open my website like this.

http://mysiste.com/contactus

it is not showing map and showing following error.

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"

while if i open my site like this.

http://www.mysiste.com/contactus

the maps are working perfectly.

My Credential Page where i add domain like this.

enter image description here

so why it is not showing maps without www?

Community
  • 1
  • 1
Hamza Zafeer
  • 2,360
  • 13
  • 30
  • 42

2 Answers2

3

*.comprettainsurance.com/* does not match http://comprettainsurance.com/contactus (it matches any subdomain of comprettainsurance.com, but not the domain itself).

You need to add an additional referrer line:

comprettainsurance.com/*
geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • should i also add this referrers in the list. `*.comprettainsurance.com/contactus*` ? – Hamza Zafeer Jul 19 '16 at 13:06
  • If you want `www.comprettainsurance.com/contactus` to work, you need that one as well. – geocodezip Jul 19 '16 at 13:14
  • is it not generic i means i just add one line and should work on all pages of website? – Hamza Zafeer Jul 19 '16 at 13:30
  • Sorry, I read your comment wrong. If you want `http://www.comprettainsurance.com/contactus` to work you need `*.comprettainsurance.com/*` also (or `www.comprettainsurance.com/*`). – geocodezip Jul 19 '16 at 13:36
  • `*.comprettainsurance.com/*` i need this line to work `www` and for all pages of website, and i need this line `comprettainsurance.com/*` to work without `www`. and for all pages without `www` is i correct understand you? please – Hamza Zafeer Jul 19 '16 at 13:48
1

Use simple like this this worked for me everywhere

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

when you use defer the script will be loaded when the document is closed- the content has been loaded. Furthermore external deffered scripts will be parsed after inline defferred scripts.