放置API - 获取地点照片作为标记图标 [英] Place API - getting place photo as marker icon

查看:84
本文介绍了放置API - 获取地点照片作为标记图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循本指南
https://developers.google .com / maps / documentation / javascript / places#places_photos
将地点照片创建为标记图标。这是我的地图初始化代码:

  var map; 

函数initMap(){
//创建一个以Pyrmont,Sydney(澳大利亚)为中心的地图。
map = new google.maps.Map(document.getElementById('map'),{
center:{lat:-6.920812,lng:107.604116},
zoom:13
});
$ b var request = {
location:map.getCenter(),
radius:'5000',
type:['shopping_mall']
} ;

var service = new google.maps.places.PlacesService(map);
service.textSearch(request,callback);
}

//检查PlacesServiceStatus是否正确,并使用PlacesService中的地点ID和位置添加标记
//。
函数回调(结果,状态){
console.log(results);
if(status == google.maps.places.PlacesServiceStatus.OK){
for(var i = 0; i< results.length; i ++){
var place = results [一世];
createPhotoMarker(place);
}
}
}

google.maps.event.addDomListener(window,'load',initMap);

这是createPhotoMarker函数

 函数createPhotoMarker(place){
var photos = place.photos;
if(!photos){
var marker = new google.maps.Marker({
map:map,
position:place.geometry.location,
title :place.name
});
return;


var marker = new google.maps.Marker({
map:map,
position:place.geometry.location,
title: place.name,
图标:照片[0] .getUrl({'maxWidth':35,'maxHeight':35})
});
}

如果放置照片不可用,该功能将创建常规标记。但是对于有照片可用的地方,我收到此错误:


加载资源失败:服务器响应状态为404() lh3.googleusercontent.com / w35-h35-p / AF1QipOIL6GVVmtqp_cw_hBEQxdILZSa8poMO0HAqFHd = k


而地图只显示常规标记。
我做错了什么?

这是小提琴 http://jsfiddle.net/v90fmrhp/
p>

==========更新2017-07-07 ============


感谢您的答案并修正

这似乎解决了问题。我的小提琴正在工作
https://issuetracker.google.com/issues/63298126


标记为固定
好​​消息!我们已经解决了这个问题。谢谢你的耐心。


快乐贴图!



解决方案

看起来像错误你看到的是由谷歌方面的一些问题引起的。它也影响到其他一些用户,看看他们的公共问题跟踪器:


感谢您报告此问题。我们对其进行了验证,我们会继续跟踪它。
https://issuetracker.google.com/issues/63298126


UPDATE(2017-07-06): $ b


现在我们的发布过程已经进入修复阶段,应该很快就会出来 - 可能最晚是星期一。
https://issuetracker.google.com/issues/63298126#comment13



I follow this guide https://developers.google.com/maps/documentation/javascript/places#places_photos to create place photo as marker icon. This is my map initialization code:

var map;

function initMap() {
    // Create a map centered in Pyrmont, Sydney (Australia).
      map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: -6.920812, lng: 107.604116},
        zoom: 13
      });

      var request = {
        location: map.getCenter(),
        radius: '5000',
        type: ['shopping_mall']
      };

      var service = new google.maps.places.PlacesService(map);
      service.textSearch(request, callback);
}

// Checks that the PlacesServiceStatus is OK, and adds a marker
// using the place ID and location from the PlacesService.
function callback(results, status) {
  console.log(results);
  if (status == google.maps.places.PlacesServiceStatus.OK) {
      for (var i = 0; i < results.length; i++) {
        var place = results[i];
        createPhotoMarker(place);
      }
  }
}

google.maps.event.addDomListener(window, 'load', initMap);

this is the createPhotoMarker function

function createPhotoMarker(place) {
      var photos = place.photos;
      if (!photos) {
        var marker = new google.maps.Marker({
            map: map,
            position: place.geometry.location,
            title: place.name
          });
          return;
      }

      var marker = new google.maps.Marker({
        map: map,
        position: place.geometry.location,
        title: place.name,
        icon: photos[0].getUrl({'maxWidth': 35, 'maxHeight': 35})
      });
}

the function will create regular marker if place photo is not available. But for the place with photo available, I get this error :

Failed to load resource: the server responded with a status of 404 () lh3.googleusercontent.com/w35-h35-p/AF1QipOIL6GVVmtqp_cw_hBEQxdILZSa8poMO0HAqFHd=k

And the map only shows regular marker. What did I do wrong?
This is the fiddle http://jsfiddle.net/v90fmrhp/

==========Update 2017-07-07============

Thanks for the answers and fixes
It seems the issue solved. My fiddle is working now https://issuetracker.google.com/issues/63298126

Marked as Fixed
Good news! We have fixed this issue. Thanks for your patience.

Happy Mapping!

解决方案

Looks like the error you are seeing is caused by some issue on Google's side. It's affecting quite a few other users as well, have a look at their public issue tracker:

Thanks for reporting this issue. We verified it and we'll keep tracking it. https://issuetracker.google.com/issues/63298126

UPDATE (2017-07-06):

A fix for this is going into our release process now and it should be out soon - probably Monday at the latest. https://issuetracker.google.com/issues/63298126#comment13

这篇关于放置API - 获取地点照片作为标记图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆