dousi1097 2014-09-30 13:06
浏览 42

我试图为两个不同的函数使用相同的代码。但是一个函数正在工作,但另一个函数不工作

These are the two functions being called, one from HTML code and one from PHP code.The function addMarker is used to add a Marker at the place which is retrieved from the database. The function codeAddressis used to place a marker at a location which is entered by the user in HTML form. The codeAdress is working fine but `addMarker' is not. I have also tried executing alert message in the addMarker function and its working fine. However the geocoder function is not working inside it. I am also writing the function calls for both the functions below the actual code.

function addMarker(address1)
{ 
geocoder.geocode( {'address': address1}, function(results, status) {
alert(address1);    
  if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        draggable: true,
        position: results[0].geometry.location
    });

  } else {
    alert("Geocode was not successful for the following reason: " + status);
  }
});

}



function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    var marker = new google.maps.Marker({
        map: map,
        draggable: true,
        position: results[0].geometry.location

    });
  }
  else {
    alert("Geocode was not successful for the following reason: " + status);
  }
});
}

The html code

<input id="address" type="textbox" value="Sydney, NSW">
<input type="button" value="Geocode" onclick="codeAddress()">

The PHP code

echo "<script type='text/javascript'>";
echo "addMarker('$row[address]')";
echo "</script>";   
  • 写回答

2条回答 默认 最新

  • dravpuso44681 2014-09-30 13:22
    关注

    $row[address] is not being evaluated here, it's just being echoed. I suspect you meant:

    echo "addMarker(" . $row['address'] . ")";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大