Jump to content

PHP code to capture and store google map drawings into postgresql


Emmy5

Recommended Posts

Hello,

 

I have written a code to use google map drawing tools to draw polygon, circle and point on the googlemap, i need to capture and store these drawing in my postgresql database and also be able to display the store data back on the map when queried.

I need someone to look at my code and tell me how I can achieve this.

The google map and the drawings functions well, i know i need to create a table in the database to capture the geometric information of the drawings which i have also done. but the table doesnt seem to be populating. i believe something is wrong with my code and i need help from anyone who has successfully done this in the past

 

 

Thanks

<?php 
   $host        = "host=localhost";
   $port        = "port=5432";
   $dbname      = "dbname=LS";
   $credentials = "user=postgres password=carol74";

   $db = pg_connect( "$host $port $dbname $credentials"  );
   if(!$db){
      echo "Error : Unable to open database\n";
   } else {
      echo "Opened database successfully\n";
   }
   ?>
   
<!DOCTYPE html>
  <head>
    <title>LSInfo Recording tool</title>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no">
    <meta charset="utf-8">
    <style>
      html, body, #map {
        height: 90%;
        margin: 10px;
        padding: 0px
      }
    </style>
   <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true&libraries=drawing,geometry"></script>
 
 <script>
var coordinates = [];
var all_shapes = [];
 
var selectedShape;
 
 
function draw_shape()
{
    for(var i = 0; i < all_shapes.length; i++)
    {
        all_shapes[i].setMap(null);
    }
 
    for(var i = 0; i < all_shapes.length; i++)
    {
        all_shapes[i].setMap(map);
    }
}
 
 
function clearSelection()
{
    if(selectedShape)
    {
        selectedShape.setEditable(false);
        selectedShape = null;
    }
}
 
function setSelection(shape)
{
    clearSelection();
    selectedShape = shape;
    shape.setEditable(true);
}
 
function deleteSelectedShape()
{
    if (selectedShape)
    {
        selectedShape.setMap(null);
    }
}
 
function save_coordinates_to_array(newShapeArg)
{
    if(newShapeArg.type == google.maps.drawing.OverlayType.POLYGON)
    {
        var polygonBounds = newShapeArg.getPath();
 
        for(var i = 0 ; i < polygonBounds.length ; i++)
        {
            coordinates.push(polygonBounds.getAt(i).lat(), polygonBounds.getAt(i).lng());
        }
    }
    else
    {
        //alert("Not polygon");/////////////
    }   
}
 
var map;
 
function initialize()
{
    map = new google.maps.Map(document.getElementById('map'), {zoom: 12, center: new google.maps.LatLng(7.07859, 5.64392)});
 
    var drawingManager = new google.maps.drawing.DrawingManager();
    drawingManager.setMap(map);
 
    google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {
        var newShape = e.overlay;
        newShape.type = e.type;
 
        all_shapes.push(newShape);
 
        setSelection(newShape);
 
        save_coordinates_to_array(newShape);
 
        google.maps.event.addListener(newShape, 'click', function() {setSelection(newShape)});
      });
 
    google.maps.event.addListener(map, 'click', function(e) {clearSelection();});
}
 
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
	<h1>Property identifcation program</h1>
	<h2> Please Use the Tools shown on the map to markout your parcel location</h2>
    <div class="map" id="map-canvas"></div>
	<form method="post" action="" name="informarionForm" id="informarionForm" ><!--onsubmit="save_details(); return false;"-->
		<p><b></b>
    	<table width="1100" cellpadding="10" cellspacing="0" border="1" align="center">
		<tr align="center" valign="top">
		<td align="center" colspan="1" rowspan="1" bgcolor="#FF8000">
    	<table style="width:80%" >
    		<h3>sketch your property location on the Map!!</h3>
			<tr>
				Title_holder:
				<?php
					$sql =<<<EOF
					SELECT * from tblperson;
EOF;
					$ret = pg_query($db, $sql);
					echo'<select name="Title_holder">';
					while($row = pg_fetch_assoc($ret)){
					echo "<option value=".$row["person_id"].">".$row["first_name"]."</option>";
					//print_r($row);
					}
					echo '</select>';
					?>
			</tr>
            
				
				Title_Type: <?php
					$sql =<<<EOF
					SELECT * from ownership_type;
EOF;
					$ret = pg_query($db, $sql);
					echo'<select name="Ownership" id="Ownership">';
					while($row = pg_fetch_array($ret)){
					
					$id = $row["type_id"];
					if($id == $row["type_id"]){
							echo 'selected';
						}
					
					echo "<option value=".$row["type_id"].">".$row["type_description"]."</option>";
					//print_r($row);
					}
					echo '</select>';
					?>
              </tr>
			<tr>
                Select boundary identifier: 
				<?php
					$sql =<<<EOF
					SELECT * from boundaryidentificationtable;
EOF;
					$ret = pg_query($db, $sql);
					echo'<select name="boundary_identifier">';
					while($row = pg_fetch_array($ret)){
					echo "<option value=".$row["boundary_id"].">".$row["boundary_type"]."</option>";
					}
					echo '</select>';
                ?>
                </tr>

			<tr>
				Media_Type: 
				<?php
					$sql =<<<EOF
					SELECT * from lutmediatypes;
EOF;
					$ret = pg_query($db, $sql);
					echo'<select name="lutmediatypes">';
					while($row = pg_fetch_array($ret)){
					echo "<option value=".$row["media_type_id"].">".$row["media_type"]."</option>";
					}
					echo '</select>';
					?>
              </tr>
            <p></p>
              <tr>
				Select_Media: <?php
					$sql =<<<EOF
					SELECT * from tblmedia;
EOF;
					$ret = pg_query($db, $sql);
					echo'<select name="tblmedia">';
					while($row = pg_fetch_array($ret)){
					echo "<option value=".$row["media_id"].">".$row["file_name"]."</option>";
					}
					echo '</select>';
					?>
        <td>Capture boundaryline geometry  from Map </td>
				<td><input name="the_geom2" type="text" id="the_geom2" ></td></td>
			</tr>   
          
        <tr>
				<td>Capture Parcel Geometry from Map </td> 
			
				<td><input name="the_geom" type="text" id="polygeom" ></td></td>
                
			</tr>
			
            <tr>
				<td>Add your description for this parcel:</td>
				<td><textarea cols="20" name="comments" rows="3" ></textarea></td>
			</tr>
            <td> </td>
				<td>

				<input name="Submit1" type="button" onclick="save_details();" value="Submit Information." ></td>
			</tr>
            
		</table>   
     
	<p></p>
    	<table width="700" cellpadding="10" cellspacing="0" border="1">
		<tr align="center" valign="top">
		<td align="center" colspan="1" rowspan="1" bgcolor="#CCCCCC">
    	<table style="width: 100%">
    		<h3>Identify other Useful Land resources and economic trees on your parcel</h3>
			<tr>
				Landuse:<?php
					$sql =<<<EOF
					SELECT * from landusetable;
EOF;
					$ret = pg_query($db, $sql);
					echo'<select name="Landuse">';
					while($row = pg_fetch_array($ret)){
					echo "<option  value=".$row["landuse_id"].">".$row["landuse_type"]."</option>";
					}
					echo '</select>';
					?>
			</tr>
            <p></p>
           <tr>
				<td>Input Resource Name (tree; pond_water):</td>
				<td><textarea cols="20" name="comments" rows="3" ></textarea></td>
			</tr>

			<tr>
				Select media to upload(video, audio, picture or text): <?php
					$sql =<<<EOF
					SELECT * from tblmedia;
EOF;
					$ret = pg_query($db, $sql);
					echo'<select name="tblmedia">';
					while($row = pg_fetch_array($ret)){
					echo "<option value=".$row["media_id"].">".$row["file_name"]."</option>";
					}
					echo '</select>';
					?>
             
			<tr>
				<td>Preview Media(video, audio, picture or text)</td>
				<td><input name="previewVideo" type="text"></td>
			</tr>
                         
           	<tr>
				<td> </td>
				<td>

				<input name="Submit1" type="button" onclick="save_details();" value="Submit Information." ></td>
			</tr>
			
		</table>   
   
    </form>
  </body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.