相关疑难解决方法(0)

如何将Google地方限制在特定城市

我目前只限制一个国家的地方,但我也想限制一个特定的城市.任何想法如何实现?这是我目前的代码:

var autocomplete,
                    options = {
                        types: ['geocode'],
                        componentRestrictions: {country: 'est'}
                    };
                autocomplete = new google.maps.places.Autocomplete(input, options);
                google.maps.event.addListener(autocomplete, 'place_changed', function () {
                    var place = autocomplete.getPlace().formatted_address;
                    $(input).attr('value',place);
                });
Run Code Online (Sandbox Code Playgroud)

google-places-api google-places

6
推荐指数
2
解决办法
1万
查看次数

使用jQuery查询Google Places API

Google Places API现已普遍推出.我试图在jQuery中使用.ajax()调用来调用Google Places.我一直回来的错误是Uncaught SyntaxError:意外的令牌:

我正在使用jQuery 1.5.2.我也尝试了1.5.1,但结果相同.如果我能提供帮助,我宁愿不转向1.6.1.

从那以后我就把这样的ajax调用到其他API,但是我在使用Google Places时遇到了麻烦.以下是您可以使用的基本代码示例.您需要在Google控制台上提供自己的密钥(https://code.google.com/apis/console)

jQuery.noConflict();
 jQuery(document).ready(function(){

  var url = 'https://maps.googleapis.com/maps/api/place/search/json';

  jQuery.ajax({
   url: url,
   dataType: 'jsonp',
   type: 'GET',
   data:  {
     location: '33.787794,-117.853111',
     radius: 1000,
     name: 'coffee',
     key: 'your_key', // add your key here
     sensor: 'false'
     },

   // on success
   success: function(data, textStatus, jqXHR){

      console.log(data);


   },

   // on failure
   error: function (jqXHR, textStatus, errorThrown){
    console.log(jqXHR);
    console.log(textStatus);
    console.log(errorThrown);
   }
   });
 });
Run Code Online (Sandbox Code Playgroud)

jquery google-places-api

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

google-places-api ×2

google-places ×1

jquery ×1