0

I generated Browser API Key in Google Console and set referrers:

referrers in google console for my api key

Then I go to http://afriflirt.com, open JS console in browser and run this code ("Google Maps Geocoding API" enabled for this api key in settings):

var apiKey = 'AIzaSyAGpR-mG46fDbmWjJwkZZHft_xvZ_dM3cA';
$.getJSON(
    'https://maps.googleapis.com/maps/api/geocode/json?address=12345&key=' + apiKey,
    function(resp) {alert(JSON.stringify(resp));}
);

in response I see this message:

This IP, site or mobile application is not authorized to use this API key. Request received from IP address 113.180.75.109, with referer: http://afriflirt.com/

If I remove referrers - API key start working, but this is not safe. So it's a problem only when I set referrers. Tried different formats of referrers patterns, but nothing worked. Also tried to wait some time (as I saw "it may take up to 5 minutes for settings to take effect"), but it doesn't help too.

Please let me know if you have any ideas how to fix this.

1 Answers1

2

According to the documentation, you need a server key for the geocoding web service.

Create a server key, enable it for IP address: 113.180.75.109, that should work in your example (but it isn't recommended to use a server key from javascript like that, use a browser key and the Google Maps Javascript API v3 Geocoding Service).

geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • Thanks, I see "The Google Maps Geocoding API will only work with a Server key.". This is weird that it works with Browser API Key when referrers not set. I can't set certain IP address as I use key from user's browser, so server key will work for me like browser key without referrers. Another solution is to move geocoding requests to server side and filter referrers inside my code. – Dmitriy Eroshenko Jan 05 '16 at 08:16