在google api javascript中放置详细信息

在google api javascript中放置详细信息,javascript,google-maps-api-3,Javascript,Google Maps Api 3,我正在使用API显示一个地方的位置详细信息。但是,我也无法显示地图。当我试着调试java脚本时,我遇到了引用错误 service.getDetails() 我想在标记点击事件的信息窗口中显示位置详细信息。有人能帮我吗?这是我的密码 function initialize() { var map = new google.maps.Map(document.getElementById('map-canvas'), { mapTypeId: google.maps.MapTypeId.ROA

我正在使用API显示一个地方的位置详细信息。但是,我也无法显示地图。当我试着调试java脚本时,我遇到了引用错误

 service.getDetails() 
我想在标记点击事件的信息窗口中显示位置详细信息。有人能帮我吗?这是我的密码

function initialize() {
var map = new google.maps.Map(document.getElementById('map-canvas'), {
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: new google.maps.LatLng(-33.8665433, 151.1956316),
zoom: 15
});

var request = {
reference: 'CnRkAAAAGnBVNFDeQoOQHzgdOpOqJNV7K9-c5IQrWFUYD9TNhUmz5-  aHhfqyKH0zmAcUlkqVCrpaKcV8ZjGQKzB6GXxtzUYcP-muHafGsmW-1CwjTPBCmK43AZpAwW0FRtQDQADj3H2bzwwHVIXlQAiccm7r4xIQmjt_Oqm2FejWpBxLWs3L_RoUbharABi5FMnKnzmRL2TGju6UA4k'
};

var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);

service.getDetails(request, function(place, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
  var marker = new google.maps.Marker({
    map: map,
    position: place.geometry.location
  });
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.setContent(place.name);
    infowindow.open(map, this);
  });
}
 });
  }

您需要在请求中显式加载此库


地点引用仅在会话中有效。无法保存字符串并再次使用它

var request =  {
      reference: place.reference
};
google.maps.event.addListener(marker,'click',function(){
    service.getDetails(request, function(place, status) {
      if (status == google.maps.places.PlacesServiceStatus.OK) {
        var contentStr = '<h5>'+place.name+'</h5><p>'+place.formatted_address;
        if (!!place.formatted_phone_number) contentStr += '<br>'+place.formatted_phone_number;
        if (!!place.website) contentStr += '<br><a target="_blank" href="'+place.website+'">'+place.website+'</a>';
        contentStr += '<br>'+place.types+'</p>';
        infowindow.setContent(contentStr);
        infowindow.open(map,marker);
      } else { 
        var contentStr = "<h5>No Result, status="+status+"</h5>";
        infowindow.setContent(contentStr);
        infowindow.open(map,marker);
      }
    });
var请求={
参考:place.reference
};
google.maps.event.addListener(标记,'click',函数(){
service.getDetails(请求、功能(位置、状态){
if(status==google.maps.places.PlacesServiceStatus.OK){
var contentStr=''+place.name+''+place.formatted\u地址;
如果(!!place.formatted_phone_number)contentStr+='
'+place.formatted_phone_number; 如果(!!place.website)contentStr+='
'; contentStr+='
'+place.types+'

'; infowindow.setContent(contentStr); 信息窗口。打开(地图、标记); }否则{ var contentStr=“无结果,状态=“+status+”; infowindow.setContent(contentStr); 信息窗口。打开(地图、标记); } });

我正在像这样加载库,感谢您的回复。但是我现在无法使用place.reference动态获取该位置的引用。如果我使用一些静态值,如“'CNRKAAAGNBVNFDEQOOQHZGDOPOQJNV7K9-c5IQrWFUYD9TNhUmz5-AHHFQYKH0ZMACULKVCRPAKCV8ZJGQKZB6GXXTZUYCP-muHafGsmW-1CWJTPBCMK43AZPAW0FRTQADQADJ3H2BZWHVIXQICCM7R4XIQMJT-OQHFQYKH0ZMCL3L\U ROUBHARABI5FMNKNZMR2TGJU6UA4K'”;这是它的工作原理。