2017-06-13 84 views
0

我想将图像用于参数。有一个问题,但我不知道在哪里。有人能帮我吗。我怎样才能使用字符串参数进入addmarker?

这是我的div部分;在这一部分,我不确定它会占位符还是别的。在那个盒子里它会是字符串。

<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> 

这是我的addMarker函数。

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

我会在这里调用函数。

我不确定我应该在哪里使用,或者它在语法上是否正确。 var imagebox = document.getElementById('img1');

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

'imagebox'是你的''标签的对象。你应该实际发送'imagebox.value'作为参数。 – doutriforce

+0

谢谢你。这工作。我花了2小时,真的很欣赏 –

+0

没问题,交配。 – doutriforce

回答

0

你发送的,而不是一个string<input>标签作为参数。

请参见下面的例子:

function sendValue() { 
 
    var i = document.getElementById('img1'); 
 
    console.log(i); 
 
    
 
    var i = document.getElementById('img1').value; 
 
    console.log(i); 
 
}
<input id="img1" type="text" placeholder="Put your picture name"> 
 
<input type="button" value="Send" onclick="sendValue()">