Search in database (xml file)

36 views
Skip to first unread message

Daejeon

unread,
Jul 19, 2011, 12:22:56 AM7/19/11
to google-map...@googlegroups.com
http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html
function searchLocationsNear(center) {
     clearLocations
();

     
var radius = document.getElementById('radiusSelect').value;
     
var searchUrl = 'phpsqlsearch_genxml.php?lat=' + center.lat() + '&lng=' + center.lng() + '&radius=' + radius;
     downloadUrl
(searchUrl, function(data) {
       
var xml = parseXml(data);
       
var markerNodes = xml.documentElement.getElementsByTagName("marker");
       
var bounds = new google.maps.LatLngBounds();
       
for (var i = 0; i < markerNodes.length; i++) {
         
var name = markerNodes[i].getAttribute("name");
         
var address = markerNodes[i].getAttribute("address");
         
var distance = parseFloat(markerNodes[i].getAttribute("distance"));
         
var latlng = new google.maps.LatLng(
              parseFloat
(markerNodes[i].getAttribute("lat")),
              parseFloat
(markerNodes[i].getAttribute("lng")));

         createOption
(name, distance, i);
         createMarker
(latlng, name, address);
         bounds
.extend(latlng);
       
}
       map
.fitBounds(bounds);
       locationSelect
.style.visibility = "visible";
       locationSelect
.onchange = function() {
         
var markerNum = locationSelect.options[locationSelect.selectedIndex].value;
         google
.maps.event.trigger(markers[markerNum], 'click');
       
};
     
});
   
}

Can someone please help? I want to perform search in my own database. The normal search process is: search in database, if match then create marker. 
What if I created the markers already in the very beginning window load? Which means below coding already in very beginning function load()
downloadUrl(datasource.xml, function(data) {
       
var xml = parseXml(data);
       
var markerNodes = xml.documentElement.getElementsByTagName("marker");
       
var bounds = new google.maps.LatLngBounds();
       
for (var i = 0; i < markerNodes.length; i++) {
         
var name = markerNodes[i].getAttribute("name");
         
var address = markerNodes[i].getAttribute("address");
         
var distance = parseFloat(markerNodes[i].getAttribute("distance"));
         
var latlng = new google.maps.LatLng(
              parseFloat
(markerNodes[i].getAttribute("lat")),
              parseFloat
(markerNodes[i].getAttribute("lng")));


My marker is already display on the map. The search function that I would like to perform is something like, when I search for some particular marker, it will zoom or bring me to that particular marker. 
How could I perform my search in this case? I tried to use the string comparison, but that method, user have to remember every marker's address or name in order to search.
Thank you so much for your suggestion and any recommendation. Thanks

xelawho

unread,
Jul 19, 2011, 12:34:16 AM7/19/11
to Google Maps JavaScript API v3
The search function that I would
> like to perform is something like, when I search for some particular marker,
> it will zoom or bring me to that particular marker.

the search parameters are kind of up to you to design, although I
imagine adding an autosuggest to the input field may make life easier
for the user. once you narrow the search down to one marker, the other
bit would be just a question of getPosition, setCenter and setZoom, no?

Daejeon

unread,
Jul 19, 2011, 2:15:47 AM7/19/11
to google-map...@googlegroups.com
How can I search in my own database? Example above is using Geocode, however, the problem is it depend on geocode database instead of mine. 
Is there any method to search other than geocode? 

Regarding to this post of Mike Williams

If I store address in xml file, example:  http://econym.org.uk/gmap/example_geomulti.htm
I should be able to find the address in the xml file right? 
However, I couldn't. 

Is there anyone have idea, what mistake I did?

xelawho

unread,
Jul 19, 2011, 3:09:55 AM7/19/11
to Google Maps JavaScript API v3
> I should be able to find the address in the xml file right?
> However, I couldn't.
>
> Is there anyone have idea, what mistake I did?

just loop through the names or addresses or whatever you're searching
for and compare it for a match against whatever's entered in the input
box.

have a look at the searchLocations function here if you're still
confused:
http://xelawho.com/map/
Reply all
Reply to author
Forward
0 new messages