我目前有一些代码,当您按下提交按钮时,应根据下拉列表框中的值在地图上放置一个标记。我已经做到了,下拉框中的值将通过 PHP 代码的 GET 表单方法进入 URL,并且还将通过参数将值传递给 javascript 函数。
我遇到的问题是我必须按两次提交按钮才能使标记出现在地图上。这不太理想,我正在寻找一些帮助来尝试解决这个问题。谢谢。
这是javascript函数代码:
function placeMarker(address)
{
// ... Set up map code here
var map = new google.maps.Map(document.getElementById("universityMap"), myOptions);
<?php
$uniname = $_GET['uninames'];
//Get the Uni code according to the uni name
$queryUniID = $mysqli->prepare("SELECT IdCode FROM universityid WHERE UniName = ?");
$queryUniID->bind_param('s', $uniname);
$queryUniID->execute();
$queryUniID->bind_result($unicode);
$queryUniID->fetch();
$queryUniID->close();
//Load the question data into relevant variables
$queryQuestions = $mysqli->prepare("SELECT QuestionNo, Answered1, Answered2, Answered3, Answered4, Answered5 FROM nssdata WHERE UniID = ?");
?>
address = address + ", UK";
geocoder.geocode({'address': address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
marker = new google.maps.Marker(
{
map: map,
position: results[0].geometry.location,
title: address,
draggable: false
});
}
else
{
alert(status);
}
});
}
这是我的html表单:
<form action="#" onsubmit="placeMarker(this.uninames.value)" method="get">