gpt4 book ai didi

javascript - 谷歌地图 API : How to place images in the content of Multiple InfoWindows?

转载 作者:行者123 更新时间:2023-11-29 10:47:38 26 4
gpt4 key购买 nike

简而言之,我想结合这两个主题:

How to add an image to InfoWindow of marker in google maps v3?

Google Maps JS API v3 - Simple Multiple Marker Example

我将我的位置数据存储在数据库中,并以数组形式检索。我想为数据库中 x 个位置中的每个位置放置一个标记和信息窗口。其中一个字段包含一个图像,我想将其包含在 infoWindow 内容中。

这是我目前的位置:

PHP: //创建连接 $con=mysqli_connect("*****","*******","*******","测试");

// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT Name, Latitude, Longitude, Image FROM locate_coords");


while($row = mysqli_fetch_array($result))
{
$users[]= $row;

}

Javascript 函数初始化():

<?php
$js_array = json_encode($users);
echo "var locations = ". $js_array . ";\n";
?>

var styles = [
{
stylers: [
{ hue: "#00ffe6" },
{ saturation: -20 },
]
},{
featureType: "road",
elementType: "geometry",
stylers: [
{ lightness: 100 },
{ visibility: "simplified" },
]
},{
featureType: "road",
elementType: "labels",
stylers: [
{ visibility: "off" }
]
}
];

var styledMap = new google.maps.StyledMapType(styles,
{name: "Styled Map"});

var mapProp = {
zoom: 12,
center: new google.maps.LatLng(51.508742,-0.120850),
mapTypeControlOptions: {
mapTypeIds: [google.maps.MapTypeId.ROADMAP, 'map_style']
}
};

var map = new google.maps.Map(document.getElementById('map-canvas'),
mapProp);


var infowindow = new google.maps.InfoWindow();
var marker, i;

for (i = 0; i < locations.length; i++) {

//var container = document.getElementById("photo");

//var img = new Image();
//img.src = '
//container.appendChild(img);

marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});

google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
//infowindow.setContent('<img id=="photo">' + locations[i][0]);
infowindow.setContent('<img src=/uploads/'. locations[i][3]'>' + locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));

}

map.mapTypes.set('map_style', styledMap);
map.setMapTypeId('map_style');
}

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

放入普通图像 url 效果很好,但是一旦我尝试放入数组值, map 就不想加载了!在这一点上,我真的可以用一个清醒的头脑来告诉我该怎么做:-(..

最佳答案

这行有错别字

infowindow.setContent('<img src=/uploads/'. locations[i][3]'>' + locations[i][0]);

.不是串联运算符,并且在 locations[i][3]'>' 之间根本没有串联运算符。正确的代码是:

infowindow.setContent('<img src=/uploads/' + locations[i][3] + '>' + locations[i][0]);

关于javascript - 谷歌地图 API : How to place images in the content of Multiple InfoWindows?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16663245/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com