1

我正在按照谷歌地图的教程将叠加层保存到 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 对多边形几何来说是否足够大?

4

1 回答 1

3

我使用下一个代码来获取坐标,然后将它们传递给一个字段以在表单中处理它。

function draw() { 
 if (drawingManager <= 0) then 

var drawingManager = new google.maps.drawing.DrawingManager({
      drawingMode: google.maps.drawing.OverlayType.POLYGON,
      drawingControl: true,
      drawingControlOptions: {
        position: google.maps.ControlPosition.TOP_CENTER,
        drawingModes: [
         // google.maps.drawing.OverlayType.MARKER,
          //google.maps.drawing.OverlayType.CIRCLE,
          google.maps.drawing.OverlayType.POLYGON,
         // google.maps.drawing.OverlayType.POLYLINE,
         // google.maps.drawing.OverlayType.RECTANGLE
        ]
      },
      markerOptions: {
        icon: 'images/beachflag.png'
      },
      polygonOptions: {
        fillColor: '#1E90FF',
        fillOpacity: 0.4,
        strokeWeight: 2,
        clickable: true,
        editable: true,
        zIndex: 1
      }
    });


    var coord_listener = google.maps.event.addListener(drawingManager, 'polygoncomplete', function (polygon) {
    var coordinates = (polygon.getPath().getArray());


    alert(coordinates);
    grabarPoligonoMysql(coordinates);
    window.poly = polygon;
});



    drawingManager.setMap(map);


} 

function PassPolygonToField(coordinates) {
//here I pass the coords to the form field and then I insert the form into a mysql database.
document.getElementById('myField').value = (coordinates);

}
于 2012-12-20T15:47:56.170 回答