Hi guys,

can someone plz help me out, i have been trying to sort out this
problem for weeks.

My map is  based on a tutorial that show how to create a store
locator.

My goal:
I want create map using the API, that allow users to search for a
specific building or famous site in UK. The users types in the a site
name/address and clicks on search, the search word is passed to my
server which matches the keyword with the data stored in the mysql
database and generate a temp xml file.  the map will read the xml and
update with a marker/s showing the location and information in a
InfoWindow. The site is currently running locally on my pc, so I don’t
know how to upload all the files to the net/

The problem:
I have one database, one phpsqlsearch_genxml.php and index.html file,
code for these I posted below. The phpsqlsearch_genxml.php file looks
and runs fine, I think the error is the index file.   So the problem
is that when the users enter a name of the site and clicks search, no
markers appear on the map and the error appears saying  in the side
bar saying “No results found.”.    But if I change the button type to
SUBMIT(index file) and then run it and type in a keyword the correct
result appear but in xml format on another page.

can some one point out what i am doing wrong.


If more info is needed plz contact me,

Thanks.
.


--------------------------------------------   Index file
----------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml";>
    <head>
        <meta http-equiv="content-type" content="text/html;
charset=utf-8"/>
        <title></title>
        <script src="http://maps.google.com/maps?
file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ-
jjS7dYxSPW5CJgpdgO_s4yyMovOaVh_KvvhSfpvagV18eOyDWu7VytS6Bi1CWxw"
                type="text/javascript"></script>
        <script type="text/javascript">
            //<![CDATA[
            var map;
            var geocoder;

            function load() {
                if (GBrowserIsCompatible()) {
                    geocoder = new GClientGeocoder();
                    map = new GMap2(document.getElementById('map'));
                    map.addControl(new GSmallMapControl());
                    map.addControl(new GMapTypeControl());
                    map.setCenter(new GLatLng(52.01903, -0.77043),8);
                }
            }


            function searchLocations() {
                var address = document.getElementById
('addressInput').value;
                geocoder.getLatLng(address, function(latlng) {
                    if (!latlng) {
                        alert(address + ' not found');
                    } else {

                        //$addressInput=$_POST['addressInput'];
                        searchLocationsNear(latlng);


                    }
                });



            }

            function searchLocationsNear(center, address) {



                GDownloadUrl("phpsqlsearch_genxml.php", function(data)

                {
                    var xml = GXml.parse(data);
                    var historicsitedata =
xml.documentElement.getElementsByTagName('marker');
                    map.clearOverlays();

                    var sidebar = document.getElementById('sidebar');
                    sidebar.innerHTML = '';






                    if (historicsitedata.length == 0) {
                        sidebar.innerHTML = 'No results found.';
                        map.setCenter(new GLatLng(52.01903, -0.77043),
8);

                        return;
                    }

                    var bounds = new GLatLngBounds();
                    for (var i = 0; i < historicsitedata.length; i++)
{
                        var name = historicsitedata[i].getAttribute
('name');
                        var address = historicsitedata[i].getAttribute
('address');
                        var point = new GLatLng(parseFloat
(historicsitedata[i].getAttribute('lat')),
                        parseFloat(historicsitedata[i].getAttribute
('lng')));

                        var marker = createMarker(point, name,
address);
                        map.addOverlay(marker);
                        var sidebarEntry = createSidebarEntry(marker,
name, address);
                        sidebar.appendChild(sidebarEntry);
                        bounds.extend(point);
                    }

                    map.setCenter(bounds.getCenter(),
map.getBoundsZoomLevel(bounds));
                });
            }

            function createMarker(point, name, address) {
                var marker = new GMarker(point);
                var html = '<b>' + name + '</b> <br/>' + address;
                GEvent.addListener(marker, 'click', function() {
                    marker.openInfoWindowHtml(html);
                });
                return marker;
            }

            function createSidebarEntry(marker, name, address) {
                var div = document.createElement('div');
                var html = '<b>' + name + '</b> <br/>' + address;
                div.innerHTML = html;
                div.style.cursor = 'pointer';
                div.style.marginBottom = '5px';
                GEvent.addDomListener(div, 'click', function() {
                    GEvent.trigger(marker, 'click');
                });
                GEvent.addDomListener(div, 'mouseover', function() {
                    div.style.backgroundColor = '#CCFFCC';
                });
                GEvent.addDomListener(div, 'mouseout', function() {
                    div.style.backgroundColor = '#FFFFFF';
                });
                return div;
            }
            //]]>
        </script>
    </head>

    <body onload="load()" onunload="GUnload()">
        <form method="post" action="phpsqlsearch_genxml.php"  >

            <!--- onsubmit="updateMarkers();return false" --->
            Address: <input type="text" name="addressInput"
id="addressInput"/>
            <input  type="button"  onclick="searchLocations()"
value="Search Locations"/>

        </form>

        <br/>


        <br/>
        <div style="width:600px; font-family:Arial,
             sans-serif; font-size:11px; border:1px solid black">
            <table>
                <tbody>
                    <tr>
                        <td width="200" valign="top"> <div
id="sidebar" style="overflow: auto; height: 400px; font-size: 11px;
color: #000"></div>

                        </td>
                        <td> <div id="map" style="overflow: hidden;
width:400px; height:400px"></div> </td>
                    </tr>
                </tbody>
            </table>
        </div>
    </body>
</html>


-------------------------------------   phpsqlsearch_genxml.php
----------------------


<?php
require("phpsqlsearch_dbinfo.php");

// Get parameters from URL
$center_lat = $_GET["lat"];
$center_lng = $_GET["lng"];

$addressInput=$_POST['addressInput'];

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

// Opens a connection to a mySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die("Not connected : " . mysql_error());
}

// Set the active mySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ("Can\'t use db : " . mysql_error());
}


///////////////////////////////////////////////////////  pass search
input to here
$query = "SELECT * FROM sitedata  WHERE name = '$addressInput'";



$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
//mysql_fetch_array
while ($row = @mysql_fetch_assoc($result)){
  $node = $dom->createElement("marker");
  $newnode = $parnode->appendChild($node);
  $newnode->setAttribute("id", $row['id']);
  $newnode->setAttribute("name", $row['name']);
  $newnode->setAttribute("address", $row['address']);
  $newnode->setAttribute("lat", $row['lat']);
  $newnode->setAttribute("lng", $row['lng']);


}



echo $dom->saveXML();
?>






--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/Google-Maps-API?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to