Dear all!
I have a final year project on Google maps. The aim of the project create a map for a farm land in a city and to read the data to be displayed on the maps from a database. But the thing is I need someone who has done something in relation with these to give me an hint on how to go about it.

Thanks in advance.

Could you perhaps create a screenshot of what you want to achieve ? It looks like you want to create polygons on a google map, as documented here.

You have to make database of location which contains Latitude and Longitude of Farm Land and name of location.

So your database is as below.

Farm_id
Farm_Name
Latitude
Longitude

Then start collecting data. Now the main thing is Integrate google map in to your website

Now see the above tutorial i linked, where every thing is given ready. The database given at there is as below

id
province
code
area
latitude
longitude
pincode

In this field you need change just name as per your requirements. Read above step by stem tutorial to integrate Google Map

I hope this will help you!

thanks it really help but i needed to mark some area for big animal and some area for small animals and other area for bigger animals. is there any idea on how i can do that on the map. i needed to do that with different colors.

Hi


http://mapsite.in/gtu/ see this website which totally based on google map. You get much more idea form this site.

Right Side corner of this website page there is Show Gtu Sankul click on it, i think this functionality you need in your map.

Please take help of JQuery.

@keval i saw the web it was cool it was exactly what am trying to do but i have a lil problem generating the xml i got the following error:[IMG]http://localhost/Google_Map/xmlgen.php[/IMG]

and here is the xml generator code:

<?php  
// Start XML file, create parent node
$dom = new DOMDocument("1.0");
$node = $dom->createElement("hunt");
$parnode = $dom->appendChild($node); 

// Opens a connection to a MySQL server

$connection=mysql_connect ('localhost', 'root', 'success123');
if (!$connection) {  die('Not connected : ' . mysql_error());} 

// Set the active MySQL database

$db_selected = mysql_select_db('club', $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
} 

// Select all the rows in the markers table

$query = "SELECT * FROM hunt WHERE 1";
$result = mysql_query($query);
if (!$result) {  
  die('Invalid query: ' . mysql_error());
} 

header("Content-type: text/xml"); 

// Iterate through the rows, adding XML nodes for each

while ($row = @mysql_fetch_assoc($result)){  
  // ADD TO XML DOCUMENT NODE  
  $node = $dom->createElement("hunt");  
  $newnode = $parnode->appendChild($node);   
  $newnode->setAttribute("City",$row['City']);
  $newnode->setAttribute("Village", $row['Village']);
  $newnode->setAttribute("Area",$row['Area']);
  $newnode->setAttribute("Predators", $row['Predators']);
  $newnode->setAttribute("Small", $row['Small']);    
  $newnode->setAttribute("lat", $row['lat']);  
  $newnode->setAttribute("lng", $row['lng']);  
  $newnode->setAttribute("type", $row['type']);
} 

echo $dom->saveXML();

?>

the error said this

This page contains the following errors:

error on line 2 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.

and i try to figure that line but i couldnt help my situation. please any suggestion can be of use here.

Emmas4,

Thinking macroscopically, you need first to devise a development strategy.

I suggest you proceed as follows:

  1. Hand-code an initial XML file.
  2. Develop client-side interpretation of the XML (ie. javascript/Google Maps). Adjust XML file as required, as your ideas develop.
  3. Work up database structure to accommodate all the data you know the XML will need.
  4. Populate database with data.
  5. Develop PHP to query database and build XML to the schema you developed earlier.

Plan on at least 50% of the available time to be spent in stage 2.

From what I read above you appear to be writing your php too early in the overall development process.

Get the strategy right and you then know exactly what you are working towards at all times, and you will minimise the need to revisit earlier code.

Airshow

@Airshow,

You might want to explain further what you mean by hand coding my initial xml file.
firstly i dont have much background on xml. and i dont have initial xml file either all am trying to do is to generate an xml file for my google maps application i have the data on my WAMPServer anll i want to do is to parse the xml generated to my google map. maybe you might give me more hint on that.

Emmas4,

In my experience, this type of application is best addressed by starting in the middle then working out, as I described.

My suggested strategy assumes that you are starting with nothing. If any of the elements (database, php script, xml schema, client-side code) already exist then you may choose a different strategy.

You might want to explain further what you mean by hand coding my initial xml file.

Hand coding: Open editor, new file, paste xml declaration, then start typing. To start, code up the XML necessary for just one farm area. This will allow you very quickly to get started with my stage 2.

... all am trying to do is to generate an xml file for my google maps application

Yes but I am suggesting that you start with something simpler - namely hand-coded xml. It will be much quicker to change as your ideas develop. Otherwise you will need to revisit both the database and the php script each time you discover a new data item that is necessary to build your map overlay. One class of data that is clearly missing from your sample php script is the polygon data. One solitary (lat,long) pair will give a point, not the polygon that you need, if I understand correctly. (You liked keval_hack's reference to http://mapsite.in/gtu/).

i have the data on my WAMPServer anll i want to do is to parse the xml generated to my google map.

Do you have ALL the data, including the polygon coordinates? And is the client-side code already complete and debugged? If so then continue writing the php script. If not, then consider my approach, under which the php script will be last element to be written.

Airshow

all i have is the first code i posted which i got from google api and the following code

<!DOCTYPE html >
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <title>PHP/MySQL & Google Maps Example</title>
    <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
    <script type="text/javascript">
    //<![CDATA[

    var customIcons = {
      restaurant: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_blue.png',
        shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
      },
      bar: {
        icon: 'http://labs.google.com/ridefinder/images/mm_20_red.png',
        shadow: 'http://labs.google.com/ridefinder/images/mm_20_shadow.png'
      }
    };

    function load() {
      var map = new google.maps.Map(document.getElementById("map"), {
        center: new google.maps.LatLng(62.9, 28.0333),
        zoom: 13,
        mapTypeId: 'roadmap'
      });
      var infoWindow = new google.maps.InfoWindow;

      // Change this depending on the name of your PHP file
      downloadUrl("phpsqlajax_genxml.php", function(data) {
        var xml = data.responseXML;
        var markers = xml.documentElement.getElementsByTagName("marker");
        for (var i = 0; i < markers.length; i++) {
          var name = markers[i].getAttribute("name");
          var address = markers[i].getAttribute("address");
          var type = markers[i].getAttribute("type");
          var point = new google.maps.LatLng(
              parseFloat(markers[i].getAttribute("lat")),
              parseFloat(markers[i].getAttribute("lng")));
          var html = "<b>" + name + "</b> <br/>" + address;
          var icon = customIcons[type] || {};
          var marker = new google.maps.Marker({
            map: map,
            position: point,
            icon: icon.icon,
            shadow: icon.shadow
          });
          bindInfoWindow(marker, map, infoWindow, html);
        }
      });
    }

    function bindInfoWindow(marker, map, infoWindow, html) {
      google.maps.event.addListener(marker, 'click', function() {
        infoWindow.setContent(html);
        infoWindow.open(map, marker);
      });
    }

    function downloadUrl(url, callback) {
      var request = window.ActiveXObject ?
          new ActiveXObject('Microsoft.XMLHTTP') :
          new XMLHttpRequest;

      request.onreadystatechange = function() {
        if (request.readyState == 4) {
          request.onreadystatechange = doNothing;
          callback(request, request.status);
        }
      };

      request.open('GET', url, true);
      request.send(null);
    }

    function doNothing() {}

    //]]>

  </script>

  </head>

  <body onload="load()">
    <div id="map" style="width: 900px; height: 630px"></div>
  </body>

</html>

and of course the table i created in my MySQL database via Wampserver perharps you might take a look at it and give me litle hints too. so far your hints has been helpful i really appreciate that.

I am further persuaded of your need for my development strategy, which is my contribution to your project, not code or code reviews.

Airshow

ok i will try thats and get back to you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.