Javascript 如何在addmarker中使用字符串参数?
我想在paramater中使用图像。有个问题,但我不知道在哪里。谁能帮帮我吗 这是我的部门;在这一部分中,我不确定它是否是占位符或其他。在那个盒子里是细绳Javascript 如何在addmarker中使用字符串参数?,javascript,google-maps,google-maps-api-3,Javascript,Google Maps,Google Maps Api 3,我想在paramater中使用图像。有个问题,但我不知道在哪里。谁能帮帮我吗 这是我的部门;在这一部分中,我不确定它是否是占位符或其他。在那个盒子里是细绳 <div id="floating-panel"> <input id="latlng" type="text" value="38.96374,35.2433"> <input id="img1" type="text" placeholder="Put your picture name"> <i
<div id="floating-panel">
<input id="latlng" type="text" value="38.96374,35.2433">
<input id="img1" type="text" placeholder="Put your picture name">
<input id="submit" type="button" value="Bul">
</div>
我将在这里调用函数
我不确定我应该在哪里使用它,或者它在语法上是否正确。
var imagebox=document.getElementById('img1')
您正在发送一个
标记作为参数,而不是字符串
请参见下面的示例:
函数sendValue(){
var i=document.getElementById('img1');
控制台日志(i);
var i=document.getElementById('img1')。值;
控制台日志(i);
}
imagebox
是您的
标记的对象。实际上,您应该将imagebox.value
作为参数发送。谢谢。成功了。我花了两个小时来解决这个问题,伙计。
function addMarker(location, map, img) {
var markers = [];
var image = img + '.png';
var marker = new google.maps.Marker({
position: location,
map: map,
icon: image
});
google.maps.event.addListener(marker, 'rightclick', function(event) {
marker.setMap(null);
});
markers.push(marker);
}
function geocodeLatLng(geocoder, map, infowindow)
{
var input = document.getElementById('latlng').value;
var latlngStr = input.split(',', 2);
var latlng = {lat: parseFloat(latlngStr[0]), lng: parseFloat(latlngStr[1])};
geocoder.geocode({'location': latlng}, function(results, status)
{
if (status === 'OK')
{
if (results[1])
{
var imagebox = document.getElementById('img1');
map.setZoom(7);
map.setCenter(latlng);
addMarker(latlng, map, imagebox);
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
}
else
{
window.alert('No results found');
}
}
else
{
window.alert('Geocoder failed due to: ' + status);
}
});
}