我目前有一些代码,当你按下提交按钮时,标记应该放在地图上,根据下拉列表框中的值。我已经这样做了,下拉框中的值将通过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">
你试图批量地理编码基于大学预填充地址列表上? – pp19dd 2012-04-05 13:04:54
不,我只根据搜索按钮被按下时下拉列表中的内容做了一个地理编码 – 2012-04-05 13:09:26
为什么在你的JS函数中间有PHP代码? – puckhead 2012-04-05 13:19:26