单击按钮时,Google选取器未加载

时间:2013-12-12 09:51:06

标签: google-picker

我使用谷歌选择器使用波纹管代码选择地点的位置。 问题是,当单击文本字段时,选择器没有加载,如果我在页面加载

时加载它,则工作正常
     // The API developer key obtained from the Google Cloud Console.
  var developerKey = 'AI..............................';

   $( "#maplocation" ).click(function() {
         // Use the API Loader script to load google.picker.
      function loadPicker() {
        gapi.load('picker', {'callback': createPicker});
      }
   });


  // Create and render a Picker object for searching images.
  function createPicker() {
    var picker = new google.picker.PickerBuilder().
        addView(google.picker.ViewId.MAPS).
        setDeveloperKey(developerKey).
        setCallback(pickerCallback).
        build();
    picker.setVisible(true);
  }

  // A simple callback implementation.
  function pickerCallback(data) {
    var url = 'nothing';
    if (data[google.picker.Response.ACTION] == google.picker.Action.PICKED) {
      var doc = data[google.picker.Response.DOCUMENTS][0];
      url = doc[google.picker.Document.URL];
    }
    var message = 'You picked: ' + url;
    document.getElementById('result').innerHTML = message;
  }

1 个答案:

答案 0 :(得分:1)

我认为这是因为您没有在选择器构建器中设置oauth令牌。

var picker = new google.picker.PickerBuilder().
        addView(google.picker.ViewId.DOCUMENTS).
        setOAuthToken('').
        setDeveloperKey('').

...