我目前正在使用谷歌地图版本2(抱歉使用旧版本,请不要建议我使用V3,因为这是我们的要求).基本上,该页面应允许用户添加地点并选择该地点的类型(例如餐馆,酒吧,学校等).这些信息将添加到数据库中,并将用于切换.添加地点现在正在工作,需要重定向到另一个PHP页面(testmap.PHP),以便它将在地图中显示标记.但是,切换需要来自下拉列表中所选类型的信息.我的问题是我不知道如何将类型与每个标记“关联”.我不知道如何从“类型”下拉列表中传输数据.
附:
>第四行到最后一行是在我的addNewMarker函数onSubmit中传输地址数据的代码.
>上面的PHP代码是下拉列表,其中包含“类型”的可能值,如上所述.
>总而言之,我需要有关如何从下拉列表中获取标记类型的实际代码,并与addNewMarker函数一起传输,以便testmap.PHP可以使用数据库中的值并且可以轻松切换.
非常感谢那些能帮助我的人!
<script type="text/javascript">
if(GbrowserIsCompatible()) {
map_compatible = true;
}
/* Initialize the map this will be called when the document is loaded from: <body onl oad="initialize_map();"> */
function initialize_map() {
if( map_compatible ) {
}
function addNewMarker(newAddress){
var set;
var lat;
var longi;
if(set==null){
set=1;
geocoder = new GClientGeocoder();
geocoder.getLatLng(newAddress, function(point){
if(!point){
alert(address + " not found");
}else{
lat = point.y;
longi = point.x;
alert("The latitude of " + newAddress + " is " + lat + " and longitude is " + longi);
default_address.push([latitude,longitude]);
location.href="testmap.PHP?lat="+lat+"&longi="+longi+"&set="+set+"&newAdd="+newAddress;
}
});
}
}
function getType(type){
//markertype = type;
document.write("Hello");
}
</script>
</head>
<body onl oad="initialize_map();">
<div id="main-wrapper">
<div id="main-padding">
<div id="map_canvas"></div>
<form name="markertype_form" method = "POST" action = "addMarker.PHP" class="form">
<?PHP
@$submit = $_POST['view'];
$selectedtype = '';
if(isset($_GET)){
$connect = MysqL_connect("localhost","root","abc123");
MysqL_select_db("mapping");
$query="SELECT id,typename FROM markertypes ORDER BY typename";
$result = MysqL_query ($query);
echo "<select name='types'>";
$types = strip_tags(@$_POST['types']);
echo "<option disabled>---------------------Select---------------------</option>";
while($nt=MysqL_fetch_array($result)){
$selected = false;
// check if the current value equals the value submited
if($_POST['types'] == $nt['id']){
$selected = true;
$selectedtype = $nt['typename'];
}
// show selected attribute only if $selected is true
echo "<option value='{$nt['id']}' ". ($selected ? "selected" : "") .">{$nt['typename']}</option>";
}
echo '</select>';
echo "</select>";
echo "<input type='submit' name ='view' value='View Details'>";// Closing of list Box
echo '<br>';
}
?>
</form>
<form name="direction_form" onSubmit="addNewMarker(this.new_address.value); return false;" class="form">
Add markers? Enter the address and we will mark it for you: <input type="text" name="new_address" class="form-field" /><br /><br />
<input type="submit" value=" Mark this place! " class="form-submit" />
</form>
解决方法:
如果你在PHP中的类型选择框上放了一个id,那么你可以在上面的javascript中添加一些代码行.
下面假设“types”select元素的id为“marker-type”:
function addNewMarker(newAddress){
var set;
var lat;
var longi;
var e = document.getElementById("marker-type");
var mtype = e.options[e.selectedindex].value;
if(set==null){
set=1;
geocoder = new GClientGeocoder();
geocoder.getLatLng(newAddress, function(point){
if(!point){
alert(address + " not found");
}else{
lat = point.y;
longi = point.x;
alert("The latitude of " + newAddress + " is " + lat + " and longitude is " + longi);
default_address.push([latitude,longitude]);
location.href="testmap.PHP?lat="+lat+"&longi="+longi+"&set="+set+"&newAdd="+newAddress+"&type="+mtype;
}
});
}
}
请注意,在AddMarker函数中,我为“mtype”添加了一个新变量,它选择了选择框并获取当前选项值.
然后在下面,API调用testmap.PHP我添加了类型选择器并为其赋予了“mtype”var的值.
$_GET['type']
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。