[英]Google Maps Api Get Details Request Not Working
我在制作Google地圖時遇到了麻煩,每當用戶單擊標記時,我希望他們看到帶有圖像的信息窗口。 我已經能夠執行所有操作,但是對於圖像,我嘗試了“獲取詳細信息”請求,由於某種原因,該請求不起作用。
function createMapMarker(placeData) {
count++;
var lat = placeData.geometry.location.lat();
var lon = placeData.geometry.location.lng();
var name = placeData.formatted_address;
var bounds = window.mapBounds;
position = placeData.geometry.location;
var marker = new google.maps.Marker({
map: map,
position: position,
title: name
});
bounds.extend(new google.maps.LatLng(lat, lon));
map.fitBounds(bounds);
map.setCenter(bounds.getCenter());
getDetails();
function getDetails() {
var service = new google.maps.places.PlacesService(map);
var request = {
placeId: placeData.place_id
}
service.getDetails(request, getCallBack);
}
function getCallBack(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
infowindow(results[0]);
}
}
function infowindow(place) {
var infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent("<img src='"+place.photos[0].getUrl+"'><br>"+placeData.name+"<br>"+placeData.formatted_address+"<br>Rating:"+placeData.rating+" stars<br>");
infowindow.open(map, this);
});
}
}
要在單擊標記后將圖像顯示在“窗口”上,可以執行以下操作:
infowindow.imageView.image = UIImage(named: "image.jpg").
希望這可以幫助 :)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.