緯度と経度の値を postgresql データベースに送信するアプリがあります。そして、jquery、ajax を使用して、OpenLayers マップに更新されたポイントを適宜プロットしたいと考えています。しかし、ここで私は立ち往生しています:ボタンをクリックすると、データベース接続を備えたphpファイルが作成され、テーブルの最後のエントリが配列に保存されます。
しかし、マーカーで出力を使用しようとすると、何も起こりません。
私の関数でphpの出力値を使用する方法は?
これが私が使用しようとしているコードです。
php ファイル:
<?php
$conn = pg_connect("host=xxx port=xxx dbname=xx user=postgres password=xxx");
$result = pg_exec($conn,"Query goes here");
$numrows = pg_numrows($result);
for($ri = 0; $ri < $numrows; $ri++)
{
$row = pg_fetch_array($result, $ri);
$data = array(); // create a variable to hold the information
$lat_latest[] = $row["latitude"];
$long_latest[] = $row["longitude"]; // add the row in to the results (data) array
}
pg_close($conn);
$js_lat = json_encode($lat_latest);
echo "var javascript_lat1 = ". $js_lat . ";\n";
$js_long = json_encode($long_latest);
echo "var javascript_long1 = ". $js_long . ";\n";
?>
私のページコードは:
function init(){
//openlayers map code is here.
$("button").click(function(){
$.get("dataconn.php",function(data,status){
alert("Data:"+data+"Status:" +status);
var extra_point = new OpenLayers.Feature.Vector(
new OpenLayers.Geometry.Point(parseFloat(javascript_long1[0]),parseFloat(javascript_lat1[0])),
{some:'data'},
{externalGraphic: 'images1/marker-gold.png', graphicHeight: 16, graphicWidth: 16});
vectorLayer1.addFeatures([extra_point]);
});
});
}
</script>
</head>
<body onload='init();'>
<div id="map" style = 'width: 1075px; height: 485px'>
<button> Update </button>
</div>
更新ボタンをクリックしたときに表示されるアラートは
Data:
var javascript_lat1 = ["output of the query"];
var javascript_long1 = ["output of the query"];
Status : success
クエリ出力の値にアクセスしようとしている方法は正しいですか? 助けてください。これがばかげた質問である場合は申し訳ありません。私はjqueryが初めてです。