2011-03-31 25 views
0

我想做一個谷歌地圖,它允許用戶點擊地圖並將點保存爲起點或終點。點擊一個點後,會看到一個infowindow。我將google地圖座標更改爲我自己定義的座標。我已經在座標中建立了一個有建築物的數據庫。 也就是說,像這樣的數據庫 (x Y樓)(1,2號塔1)(1,3號塔2)使用ajax將javascript中的變量傳遞給sql server

我想傳遞座標在sql數據庫中搜索並返回建築物。並在文本框中顯示建築物名稱。但是,看起來回報並不成功。請幫幫我。我在互聯網上搜索了很長時間。

storelatlng.php

require_once("Connections/fees0_7548734_cumap.php"); 
$x = $_GET['x']; 
$y = $_GET['y']; 
$data = mysql_query("SELECT Bname FROM Coordinate WHERE X=2 AND Y=58") or die(mysql_error()); 
$info = mysql_fetch_array($data); 
$Bname = $info['Bname']; 
echo $Bname; 

mapfunction.php

var map; 
var Bname=""; 
function storelatlng(){ 
    var y = document.getElementById("Latitude").value; 
    var x = document.getElementById("Longitude").value 

    var getVars = "?y="+y+"&x="+x; 

    if (window.XMLHttpRequest) 
    {// code for IE7+, Firefox, Chrome, Opera, Safari 
     var request=new XMLHttpRequest(); 
    } 
    else 
    {// code for IE6, IE5 
     var request=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
    request.open('GET','storelatlng.php'+getVars,true); 
    request.onreadystatechange = function(){ 
     if(request.readyState == 4){ 
      var xmlDoc = request.responseText; 
      document.getElementById("frmLat").value = xmlDoc; 
     } 
    } 
    request.send(null); 
    return false; 

} 
function initialize() { 
    if (GBrowserIsCompatible()) { 

    map = new GMap2(document.getElementById("map_canvas")); 
    map.setCenter(new GLatLng(22.419161, 114.207559), 17); 
    GEvent.addListener(map,"click", 
     function(overlay,latlng){ 
      var setLat = latlng.lat(); 
      var setLon = latlng.lng(); 
      setLat = Math.floor((Math.floor(setLat*100000)-2241187)/20); 
      setLon = Math.floor((Math.floor(setLon*100000)-11420020)/20); 
      //y 
      document.getElementById("frmLat").value = setLat; 
      //x 
      document.getElementById("frmLon").value = setLon; 
      var inputForm = document.createElement("form"); 
      inputForm.setAttribute("action",""); 
      inputForm.onsubmit = function(){storelatlng(); 
      return false; 
      }; 
    inputForm.innerHTML = '<fieldset style = "width:200px;">' 
     + '<legend> Mark Point </legend>' 
     + 'Please choose it '+Bname+' your starting or ending point.'+'<p></p>' 
     + '<label><input type="radio" name="choice" value="0" id="choice_s" />Start</label>' 
     + '<label><input type="radio" name="choice" value="1" id="choice_e" />End</label>' 
     + '<input type="submit" value="Save"/>' 
     + '<input type="hidden" id="Longtitude" value="'+setLon+'"/>' 
     + '<input type="hidden" id="Latitude" value="'+setLat+'"/>'; 

    map.openInfoWindow(latlng,inputForm); 
     }); 
<?php 
+0

您是否追查問題發生的地點? 'storelatlng.php'是否收到有效的經緯度?另外,爲什麼你在'storelatlng.php'中對'X = 2和Y = 58'進行硬編碼? – dgilland 2011-03-31 03:49:01

回答

0

在最低限度,確保你的函數和函數調用正確。 GEvent.addListener缺少一個結束符(在匿名函數後面有一個分號,表示GEvent.addListener已結束),並且代碼示例末尾有一個額外的paren。初始化也看起來像缺少大括號。