2016-12-03 3 views
0

У меня здесь действительно особенная проблема. Я могу запустить код на JsFiddle, но не смог запустить точный код на Codepen. Я также не могу запустить его на своем локальном компьютере. Пожалуйста плавник ниже Ссылки-Google Map Автозаполнение не работает

CodePen Link

JsFiddle Link

JavaScript используется-

var placeSearch, autocomplete; 


function initAutocomplete() { 
    autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')), 
     {types: ['geocode']}); 

    autocomplete.addListener('place_changed', fillInAddress); 
} 

function geolocate() { 
    if (navigator.geolocation) { 
    navigator.geolocation.getCurrentPosition(function(position) { 
     var geolocation = { 
     lat: position.coords.latitude, 
     lng: position.coords.longitude 
     }; 
     var circle = new google.maps.Circle({ 
     center: geolocation, 
     radius: position.coords.accuracy 
     }); 
     autocomplete.setBounds(circle.getBounds()); 
    }); 
    } 
} 
+0

Ваш ключ не авторизован для CodePen: 'Google Maps API ошибка: RefererNotAllowedMapError https://developers.google.com/maps/documentation/javascript/error-messages#referer-not-allowed-map -error URL-адрес вашего сайта для авторизации: http: // s.codepen.io/boomerang/ee5c28f48760ef39f4ce481d5c7ac3ff1480776136374/index.html' – geocodezip

ответ

2

Если открыта консоль браузера вы увидите следующее сообщение об ошибке возникает на codepen сайте:

RefererNotAllowedMapError exception

Accordintg в Error Messages page:

The current URL loading the Google Maps JavaScript API has not been added to the list of allowed referrers. Please check the referrer settings of your API key on the Google API Console.

See API keys in the Google API Console . For more information, see Best practices for securely using API keys .

Чтобы устранить проблему:

  • пойти Google API Console
  • под Credentials меню выбора выберите соответствующий API ключ
  • в списке HTTP Referers добавить http://s.codepen.io/*

enter image description here

+1

Спасибо @ Вадим Гремячев, это сработало .. :) – theLearner

Смежные вопросы