douyingyu5573 2012-02-13 11:05
浏览 136
已采纳

php代码调用javascript函数返回函数未定义

The code bellow tries to ask the user to upload kml file and then saves the file at the same time it shows the kml data in google maps using google maps api v2. I could successfully take the kml file and saves it at a specific directory, HOWEVER, i am facing some problem in displaying the file on google maps immediately after the user clicks on KML TEST button. The error is Uncaught ReferenceError: showKML is not defined

Here is the code that I used

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>Find latitude and longitude with Google Maps</title>   
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAgrj58PbXr2YriiRDqbnL1RSqrCjdkglBijPNIIYrqkVvD1R4QxRl47Yh2D_0C1l5KXQJGrbkSDvXFA"
      type="text/javascript"></script>  

    <?php
    $upload = $_SERVER['PHP_SELF'];
    if(isset($_POST['kmltest'])) {
    $target_path = "uploads/";
    $fn =  basename( $_FILES['uploadedfile']['name']);

    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    //echo $target_path ;
    if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
    echo "<script type=\"text/javascript\"> showKML(); </script>";


    } 
    else{
    echo "There was an error uploading the file, please try again!";
    }


}
?>

    <script src="egeoxml.js" type="text/javascript"></script>
    <script  type="text/javascript">

    var map;
    var options = {};
    var shapeCounter_ = 0;


        function initialize() {
        if (GBrowserIsCompatible()) {
            map = new GMap2(document.getElementById("map"));
            map.setCenter(new GLatLng(25.22903, 55.46612), 13);
            map.addControl(new GSmallMapControl());
            map.addControl(new GMapTypeControl());
            map.clearOverlays();
            document.getElementById("lat").value = "25.22903";
            document.getElementById("lng").value = "55.46612";
        }
    }




    function startShape() {
        initialize();
        document.getElementById('lat').disabled = true;
        document.getElementById('lng').disabled = true;
        var polygon = new GPolygon([],"ff0000", 2, 0.7,"ff0000",0.2);
        startDrawing(polygon, "Shape " + (++shapeCounter_), function() {
            var cell = this;
            var area = polygon.getArea();
            cell.innerHTML = (Math.round(area / 10000) / 100) + "km<sup>2</sup>";
            });
        showcoor(polygon);
    }

    function startDrawing(poly, name, onUpdate) {
        map.addOverlay(poly);
        poly.enableDrawing(options);
        poly.enableEditing({onEvent: "mouseover"});
        poly.disableEditing({onEvent: "mouseout"});
        GEvent.addListener(poly, "endline", function() {
            GEvent.addListener(poly, "click", function(latlng, index) {
                if (typeof index == "number") {
                    poly.deleteVertex(index);
                }    
            });
        });    
    }

    function showcoor (poly) {
        GEvent.addListener(poly, "endline", function() {
            GEvent.addListener(poly, "click", function() {
                var str= "" ;
                for (var i = 0, I = this.getVertexCount(); i < I; ++i) {
                    var xy = this.getVertex(i);
                    str += xy.lat() + ', ' + xy.lng() + '<br />';
                }
                alert (str);
            });
        });
    }

    function drawpoint() {
        //initialize();
        document.getElementById('lat').disabled = false;
        document.getElementById('lng').disabled = false;
        var lat = document.getElementById('lat').value;
        var lng = document.getElementById('lng').value;
        var center = new GLatLng(parseFloat(lat),   parseFloat (lng));
        map.setCenter(center, 7);
        geocoder = new GClientGeocoder();
        var marker = new GMarker(center, {draggable: true});  
        map.addOverlay(marker);
        GEvent.addListener(marker, "dragend", function() {
            var point = marker.getPoint();
            map.panTo(point);
            document.getElementById("lat").value = center.lat().toFixed(5);
            document.getElementById("lng").value = center.lat().toFixed(5);
        });
        GEvent.addListener(map, "moveend", function() {
            map.clearOverlays();
            var center = map.getCenter();
            var marker = new GMarker(center, {draggable: true});
            map.addOverlay(marker);
            document.getElementById("lat").value = center.lat().toFixed(5);
            document.getElementById("lng").value = center.lng().toFixed(5);
            GEvent.addListener(marker, "dragend", function() {
                var point =marker.getPoint();
                map.panTo(point);
                document.getElementById("lat").value = point.lat().toFixed(5);
                document.getElementById("lng").value = point.lng().toFixed(5);
            });
        });
    }

    function showKML() {
    //alert(filename);
        initialize();
        document.getElementById('lat').disabled = true;
        document.getElementById('lng').disabled = true;
        var exml;
        exml = new EGeoXml("exml", map, ("uploads/test.kml"));
        exml.parse();
        exml.show(); 
    }



    </script>


    </head> 
<body onload="initialize()" onunload="GUnload()" >
 <form action = <?php echo $upload; ?> method = "post"  enctype="multipart/form-data"/>
 <p align="left">

 <table>
  <tr>
    <td><b>Latitude</b></td>
    <td><b>Longitude</b></td>
  </tr>
  <tr>
    <td> 
    <input type="text" name="lat" id="lat" /></td>
    <td>
    <input type="text" name="lng" id="lng" /></td>
    <td>
    <input type="button" name="point" id="point" value="Point" onclick="drawpoint()" /><td>

    <input type="button" name="shape_b" id="shape_b" value="Poly" onclick="startShape()" /><td>



    <input type="submit" name="kmltest" id="kmltest" value="KML TEST" /> </td></tr>
    <tr>
    <td>
     <input type="file" name="uploadedfile" id="uploadedfile" />
    </td>
    </tr>



</table>
 </p>
  <p>
  <div align="center" id="map" style="width: 600px; height: 400px"><br/></div>
   </p>

  <script type="text/javascript">
//<![CDATA[
if (typeof _gstat != "undefined") _gstat.audience('','pagesperso-orange.fr');
//]]>
</script>

</form>

</body>

</html>

your assistance is highly appreciated

  • 写回答

2条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 VB6.0使用WebBrowser控件打开网页总是弹出js错误提示,请解决。
      • ¥20 如何按照企业名字进行爬虫
      • ¥15 关于#单片机波形发生器频率计算#的问题,如何解决?
      • ¥100 制作短链接和api接口的
      • ¥15 星河亮点sp9500测试指导
      • ¥15 dataframe 某列数据分列
      • ¥15 风扇导入fluent后仿真压力和速度数据卡在旋转域
      • ¥15 echarts中dataZoom报错
      • ¥15 求解答:《前端综合基础》作为一门课程的话,应该包含哪些内容?
      • ¥15 软件原型系统开发+实例测试