I tried this method in full and no matter what I search, I get "no results found"
On Mar 19, 1:14 pm, "[email protected]" <[email protected]> wrote: > Also it should be noted that phpsqlsearch_genxml4.php? references the > php code at the top of my last post and is not the same code as > phpsqlsearch_genxml3.php? which is what I use for the address search. > The address search php is the same as the tutorial and is referenced > in my javascript by function searchLocations() function > searchLocationsNear(center) I create two separate functions > searchLocations2(name) and function searchLocationsNear2(name) which > you can see in the center of my last post. > > Does that make sense? If you need help implementing it let me know. > > Thanks, > > Matt > > On Mar 19, 1:09 pm, "[email protected]" <[email protected]> wrote: > > > > > Nevermind that was a bad way to do it. Here is what you have to do. > > Create a second php file that looks like this that iterates the xml > > nodes, but this time it will just be for yournamesearch. > > > <?php > > //require("phpsqlsearch_dbinfo.php"); > > > // Get parameters from URL > > $center_lat = $_GET["lat"]; > > $center_lng = $_GET["lng"]; > > $radius = $_GET["radius"]; > > $name= $_GET["name"]; > > > // Start XML file, create parent node > > $dom = new DOMDocument("1.0"); > > $node = $dom->createElement("markers"); > > $parnode = $dom->appendChild($node); > > > // Opens a connection to a mySQL server > > // put your db connection info here. > > if (!$connection) { > > die("Not connected : " . mysql_error()); > > > } > > > // Set the active mySQL database > > $db_selected = mysql_select_db(usr5118_google, $connection); > > if (!$db_selected) { > > die ("Can\'t use db : " . mysql_error()); > > > } > > > //Searchthe rows in the markers table > > $query = sprintf("SELECT address,name, email, phonenumber, company, > > lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) > > * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin > > ( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' > > ORDER BY distance LIMIT 0 , 20", > > mysql_real_escape_string($center_lat), > > mysql_real_escape_string($center_lng), > > mysql_real_escape_string($center_lat), > > mysql_real_escape_string($radius)); > > $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)){ > > $node = $dom->createElement("markers"); > > $newnode = $parnode->appendChild($node); > > $newnode->setAttribute("name", $row['name']); > > $newnode->setAttribute("address", $row['address']); > > $newnode->setAttribute("email", $row['email']); > > $newnode->setAttribute("phonenumber", $row['phonenumber']); > > $newnode->setAttribute("company", $row['company']); > > $newnode->setAttribute("lat", $row['lat']); > > $newnode->setAttribute("lng", $row['lng']); > > $newnode->setAttribute("distance", $row['distance']); > > > } > > > $query2 =sprintf("SELECT address,name, email, phonenumber, company, > > lat, lng FROM markers WHEREnameLIKE '%s'", $name. "%"); > > $result2 = mysql_query($query2); > > while ($row2 = @mysql_fetch_assoc($result2)){ > > $node = $dom->createElement("markers"); > > $newnode = $parnode->appendChild($node); > > $newnode->setAttribute("name", $row2['name']); > > $newnode->setAttribute("address", $row2['address']); > > $newnode->setAttribute("email", $row2['email']); > > $newnode->setAttribute("phonenumber", $row2['phonenumber']); > > $newnode->setAttribute("company", $row2['company']); > > $newnode->setAttribute("lat", $row2['lat']); > > $newnode->setAttribute("lng", $row2['lng']); > > $newnode->setAttribute("distance", $row2['distance']); > > > } > > > echo $dom->saveXML(); > > > ?> > > > Thenaddthis java script > > > function searchLocations2() { > > varname= document.getElementById('nameInput').value; > > searchLocationsNear2(name); > > } > > function searchLocationsNear2(name) { > > var radius = 3000; > > var searchUrl = 'phpsqlsearch_genxml4.php?name=' +name; > > GDownloadUrl(searchUrl, function(data) { > > var xml = GXml.parse(data); > > var markers = xml.documentElement.getElementsByTagName > > ('markers'); > > map.clearOverlays(); > > > var sidebar = document.getElementById('sidebar'); > > sidebar.innerHTML = ''; > > if (markers.length == 0) { > > sidebar.innerHTML = 'No results found.'; > > map.setCenter(new GLatLng(40, -100), 4); > > return; > > } > > > var bounds = new GLatLngBounds(); > > for (var i = 0; i < markers.length; i++) { > > varname= markers[i].getAttribute('name'); > > var address = markers[i].getAttribute('address'); > > var email = markers[i].getAttribute('email'); > > var phonenumber = markers[i].getAttribute('phonenumber'); > > var company = markers[i].getAttribute('company'); > > var distance = parseFloat(markers[i].getAttribute > > ('distance')); > > var point = new GLatLng(parseFloat(markers[i].getAttribute > > ('lat')), > > parseFloat(markers[i].getAttribute > > ('lng'))); > > > var marker = createMarker(point,name, address, email, > > phonenumber, company); > > map.addOverlay(marker); > > var sidebarEntry = createSidebarEntry2(marker,name, > > address,distance); > > sidebar.appendChild(sidebarEntry); > > bounds.extend(point); > > } > > map.setCenter(bounds.getCenter(), map.getBoundsZoomLevel > > (bounds)); > > }); > > } > > Then put a form on your page that looks like this. > > > <input type="text" id="nameInput"/> > > <input type="button" onclick="searchLocations2()" value="OfficeSearch"/> > > > Hope that helps! That was a cool project to implement. > > > On Mar 18, 8:35 pm, "[email protected]" <[email protected]> wrote: > > > > I was trying to go about this another way. It might be the wrong way > > > but it seemed easier. Maybe not but I seem to be hung up in one spot. > > > Instead of changing the URL I was going toadda second text box for > > > thenamein my case it is an agentsname. This second form points back > > > to the same page to find a php script in the header. Then the php > > > script query find thatnameand the address that matches to it. Then I > > > wanted to call the java script function from within the web page with > > > the php writing to the searchLocations() function upon page load. > > > > I made a second but almost identical function called searchLocations2 > > > (). This does the exact same thing as the first, but receives the > > > variable dynamically after the form is submitted. > > > > I put a document.write(address) after the variable is initialized to > > > ensure that it grabbed the address. For whatever reason though this is > > > where the program stops working. > > > > the line - geocoder.getLatLng(address, function(latlng) { > > > > appears to do nothing and I don't know why. Technically shouldn't it > > > create the map once I have fed it with the address variable? Any > > > ideas? I can paste code or give you the web site to look at. > > > > Thanks, > > > > Matt > > > > On Mar 2, 10:39 am, Barry Hunter <[email protected]> wrote: > > > > > Basic overview, > > > > > 1)adda new textbox for 'namesearch' > > > > > 2) create function that takes taht value and sends it to the server > > > > (much like the searchLocationsNear calls > > > > var searchUrl = 'phpsqlsearch_genxml_restaurant.php?lat=' + > > > > center.lat() + '&lng=' + center.lng() + '&radius=' + radius; > > > > you have > > > > var searchUrl = 'phpsqlsearch_genxml_restaurant.php?q=' + > > > > escape(query); > > > > > 3) modify the php script to check if anameis included, if it > > > > issearchthenamefield, otherwise get the lat/long andsearchas per > > > > the tutorial. > > > > > at the most basic you just do > > > > $sql = "... wherenamelike '%".mysql_real_escape_string($_GET['q'])."%' > > > > "; > > > > which will work for single keywords. Otherwise investigate the full > > > > textsearchoption in mysql . > > > > > On 02/03/2009, Nathan <[email protected]> wrote: > > > > > > So, I ran through the API tutorial to create a store locator, and it > > > > > worked like a charm. I have a MySQL database with 1000 or so > > > > > locations, and using the API example, I have everything set up to > > > > > searchby address, grab the locations from the database and show them > > > > > on a map. That works perfectly..... > > > > > > But now I want toadda field tosearchbyname. > > > > > > The client is a vodka producer. They want people to be able tosearch > > > > > by location (give me the nearest liquor store that has the product) > > > > > but also by storename(hey, I live by Joe's Liquor store, do they > > > > > have it?). > > > > > > So, thenameof the store is in the db, but how do I do asearchby > > > > > it? I don't even know where to begin. > > > > > > Here's the page that works to find a location by address: > > > > > http://www.doublecrossvodka.com/locator/find_restaurants.php > > > > > > That page hits > > > > > thehttp://www.doublecrossvodka.com/locator/phpsqlsearch_genxml_restauran... > > > > > page > > > > > > Any ideas? > > > > > > Thank you so much. > > > > > -- > > > > Barry > > > > > -www.nearby.org.uk-www.geograph.org.uk- --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
