latlang没有定义,AJAX在谷歌地图中也没有响应

latlang is not defined and no response from AJAX IN Google maps

本文关键字:响应 谷歌地图 AJAX 定义 latlang      更新时间:2023-09-26

错误:
latlng is undefined(var lng = latlng.lng(); )尽管它得到一个值并放入文本框中ajax没有响应。我希望响应为文本,而不是xml。我缺少什么?

function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
//map.addControl(new GMap2TypeControl());
map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
GEvent.addListener(map, "click", function(overlay, latlng) {
var inputForm = document.createElement("form");
inputForm.setAttribute("action","");
inputForm.onsubmit = function() {storeMarker(); return false;};
//retrieve the longitude and lattitude of the click point
var lng = latlng.lng();
var lat = latlng.lat();
inputForm.innerHTML = '<fieldset style="width:150px;">'
+ '<legend><b>Add Property<b></legend>'
+ '<label for="name"><B>Name</b></label>'
+ '<input type="text" id="name" style="width:100%;"/>'
+ '<label for="address"><b>Address</b></label>'
+ '<input type="text" id="address" style="width:100%;"/>'
+ '<label for="address"><b>Type</b></label>'
+'<select id="type"><option>Homes</option><option>Plots</option><option>Commercials</option></select>'
+ '<label for="address"><b>Prperty Type</b></label>'
+'<select id="property_type"><option>Sale</option><option>Rent</option><option>Wanted</option></select>'
+ '<label for="address"><b>Descreption</b></label>'
+ '<textarea id="description" cols="15" rows="4" name="description"></textarea>'
+ '<input type="text" id="longitude" value="' + lng + '"/>'
+ '<input type="text" id="latitude" value="' + lat + '"/>'
+ '<input type="submit" value="ADD"/>'
+ '</fieldset>';
map.openInfoWindow (latlng,inputForm);
});
}
}

这是商店标记功能:

function storeMarker(){
//alert("xainee");
var lng = document.getElementById("longitude").value; //getting the longitude
var lat = document.getElementById("latitude").value;//getting the latitude
alert(lng +"and"+lat);
//geeting the user data in form
var getVars =  "storeMarker.php?name=" + document.getElementById("name").value
+ "&address=" + document.getElementById("address").value
+ "&description=" + document.getElementById("description").value
+ "&property_type=" + document.getElementById("property_type").value
+ "&type=" + document.getElementById("type").value
+ "&lng=" + lng
+ "&lat=" + lat ;
//alert(getVars);
//////////////////////////////////////////
var Request = false;
 if (window.XMLHttpRequest) {
  Request = new XMLHttpRequest();
 } else if (window.ActiveXObject) {
  Request = new ActiveXObject("Microsoft.XMLHTTP");
 }
 if (Request) {
     alert("workinh");
     Request.open("GET","storeMarker.php"+getVars,true);
     Request.onreadystatechange=function()
  {
  if (Request.readyState==4 && Request.status==200)
    {
    document.write(responseText);
    }
  }
   Request.send(null);
}
}

这是storeMarker.php页面:

<?php
include_once('clsGeneral.php');
echo $name=$_GET['name'];
echo $address=$_GET['address'];
echo $type=$_GET['type'];
echo $property_type=$_GET['property_type'];
echo $descreption=$_GET['description'];
echo $lat=(float)$_GET['lat'];
echo $lan=(float)$_GET['lng'];
$my_query="INSERT INTO map_marker SET name='$name',
    address='$address',type='$type',property_address='$property_type',
    descreption='$descreption',lat='$lat',lan='$lat'";
db_execute($my_query);
?>

我的问题是,当Geventlistner通过点击触发时,弹出窗口显示文本框中具有纬度和经度值的所有元素,但当我在任何文本框中点击时,它显示一个错误"未定义latlan"。其次,它不发送请求,例如,它在这里不发送响应,我希望响应是字符串,而不是XML。

根据精细的谷歌地图手册:

当触发事件时,Maps API事件系统中的许多事件都会传递参数。例如,如果地图点击发生在覆盖上,则GMap2"点击"事件会传递overlayoverlaylatlng;否则,它通过地图坐标的latlng。您可以通过将指定的符号直接传递给事件侦听器中的函数来访问这些参数。

在下面的示例中,我们首先通过检查是否定义了latlng参数来测试,以确保点击是在地图瓦片上;如果是这样,我们在单击的坐标上方打开一个信息窗口,并显示转换为像素空间的坐标以及缩放级别。