錯誤:
latlng is undefined(var lng = latlng.lng();)
儘管它得到的值,並把在文本框 沒有從Ajax響應。我想要作爲文本的響應,而不是xml。我錯過了什麼?latlang沒有定義,沒有從Ajax響應在谷歌地圖
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。
您也似乎在同一時間詢問多個問題(一個是Google Maps API問題,另一個是看似不相關的AJAX問題)。如果分別詢問每個問題,StackOverflow的效果最佳。 – 2011-06-08 23:23:08