小编Ror*_*ory的帖子

谷歌地方照片getUrl()打破了我的JavaScript

我有以下javascript:

function callback(results, status) {
  if (status == google.maps.places.PlacesServiceStatus.OK) {
    for (var i = 0; i < results.length; i++) {
      place = new Object ({
        name: results[i].name,
        photo: results[i].photos[0].getUrl({'maxWidth': 100, 'maxHeight': 100}),
        loc: results[i].geometry.location,
        rating: results[i].rating,
      })
      places.push(place);
      var marker = new google.maps.Marker({
        map: map,
        position: results[i].geometry.location,
        id: i,
        visible: false,
      });
      markers.push(marker);
    }
  }
  newresult();
}
Run Code Online (Sandbox Code Playgroud)

如果我注释掉以下行,则函数newresult()将运行:

photo: results[i].photos[0].getUrl({'maxWidth': 100, 'maxHeight': 100}),
Run Code Online (Sandbox Code Playgroud)

但是,如上面的代码,如果我没有注释掉函数newresult()将不会运行.我知道照片的getUrl函数有效,因为它返回一个有效的url.

谢谢你的帮助.

geturl google-maps-api-3 google-places-api

7
推荐指数
1
解决办法
6919
查看次数

向 Google 自动完成添加自定义(获取位置)选项

我目前在我的页面上有一个样式化的 pac 输入,可与地点库中的 Google 自动完成功能一起使用。我一直试图在下拉列表的顶部添加一个获取位置的选项,但没有运气。

在此处输入图片说明

Javascript(我不是 js wiz)-

  var lat = 'empty';
    var lng = 'empty';
    var placeSearch, autocomplete;
    var place;
    var geocoder;


    function initialize() {

  geocoder = new google.maps.Geocoder();
  // Create the autocomplete object, restricting the search
  // to geographical location types.
  autocomplete = new google.maps.places.Autocomplete(
      /** @type {HTMLInputElement} */(document.getElementById('pac-input')),
      { types: ['geocode', 'establishment'], 
        componentRestrictions: {country: 'GB'}});
  // When the user selects an address from the dropdown,
  // populate the address fields in the form.
  google.maps.event.addListener(autocomplete, 'place_changed', function() { …
Run Code Online (Sandbox Code Playgroud)

autocomplete google-maps-api-3 google-places-api

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