2013-05-17 81 views
0

我正在使用API​​顯示地點的位置詳細信息。但是我也無法顯示地圖。當我試圖調試Java腳本我收到引用錯誤的在google api中放置詳細信息javascript

service.getDetails() 

我要顯示在標記的On Click事件在信息窗口位置的詳細信息。任何人都可以幫我解決這個問題。這裏是我的代碼

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); 
    }); 
} 
}); 
    } 

回答

0

的地方引用僅僅是一個會話內有效。您不能保存該字符串並再次使用它。

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); 
     } 
    }); 

Example

+0

感謝reply.But我不能夠得到那個地方的參考動態使用now.If我喜歡用一些靜態值place.reference「‘CnRkAAAAGnBVNFDeQoOQHzgdOpOqJNV7K9-c5IQrWFUYD9TNhUmz5-aHhfqyKH0zmAcUlkqVCrpaKcV8ZjGQKzB6GXxtzUYcP-muHafGsmW-1CwjTPBCmK43AZpAwW0FRtQDQADj3H2bzwwHVIXlQAiccm7r4xIQmjt_Oqm2FejWpBxLWs3L_RoUbharABi5FMnKnzmRL2TGju6UA4k’ };」這它的工作。 – user2393611