我正在按照谷歌地图的教程将叠加层保存到 mysql:https ://developers.google.com/maps/articles/phpsqlinfo_v3但我无法使用 Oracle 实现它。如果有人可以指出我的错误,这是我到目前为止的代码:
function savePolygons(){
for (var i = 0; i < createdShapes.length; i++){
var nom_zone = document.getElementById('nom_zone_' + createdShapes[i].id).value;
alert(nom_zone)
var couleur = createdShapes[i].fillColor;
alert(couleur)
var code_cs = '711';
var shapeid_export = createdShapes[i].id;
alert(shapeid_export)
var geometry = createdShapes[i].getPath().getArray();
alert(geometry)
var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
downloadUrl(url1, function(data, responseCode){
if (responseCode == 200 && data.length <= 1) {
infowindow.close();
}
});
}
}
function downloadUrl(url1, callback) {
var request = window.ActiveXObject ?
new ActiveXObject('Microsoft.XMLHTTP') :
new XMLHttpRequest;
request.onreadystatechange = function() {
if (request.readyState == 4) {
request.onreadystatechange = doNothing;
callback(request.responseText, request.status);
}
};
request.open('GET', url1, true);
request.send(null);
}
function doNothing() {}
有 oracle_savePolygons.php 的 php 代码,我在 localhost 上使用 EasyPHP:
<?php
require("oracle_dbinfo.php");
$nom_zone =$_GET['nom_zone'];
$shapeid_export = $_GET['shapeid_export'];
$code_cs = $_GET['code_cs'];
$couleur = $_GET['couleur'];
$geometry = $_GET['geometry'];
$conn = oci_connect($username, $password, $database);
$query = oci_parse($conn, 'INSERT INTO test1 (shapeid, nom_zone, code_cs, couleur, geometry) VALUES (:nom_zone, :shapeid_export, :code_cs, :couleur, :geometry)';
oci_bind_by_name($query, ":nom_zone", $nom_zone);
oci_bind_by_name($query, ":shapeid_export", $shapeid_export);
oci_bind_by_name($query, ":code_cs", $code_cs);
oci_bind_by_name($query, ":couleur", $couleur);
oci_bind_by_name($query, ":geometry", $geometry);
oci_execute($query);
oci_commit($conn);
?>
我找到了另一种解决方案:
function savePolygons(){
for (var i = 0; i < createdShapes.length; i++){
var nom_zone = escape(document.getElementById('nom_zone_' + createdShapes[i].id).value);
var couleur = escape(createdShapes[i].fillColor);
var code_cs = escape('711');
var shapeid_export = escape(createdShapes[i].id);
var geometry = createdShapes[i].getPath().getArray();
var url1 = "oracle_savePolygons.php?nom_zone=" + nom_zone + "&couleur=" + couleur + "&code_cs=" + code_cs + "&shapeid_export=" + shapeid_export + "&geometry=" + geometry;
window.location.href = url1 ;
}
}
它可以工作,但我想知道使用 window.location.href 是否是一个安全的解决方案。在 test1 表的 oracle GEOMETRY CLOB var 中插入几何数组时,我也遇到了问题。我有一个 oci_execute 错误,我不知道为什么。4000 字节的 varchar 对多边形几何来说是否足够大?