Hi all,
First my apologies not posting a web link because this is not a web
page application. I'm using the Google Maps API and Google AJAX Search
API with my MFC application.
In my C++ program, I'll call the JavaScript functions in a html file
to perform a search. What I expect is that when the search is
completed, the results will be recorded as a text file and the
JavaScript function will return a status update so that I can read the
text file. The codes are attached in the end.
However, the callback function is not executed properly. I found it
interesting that if I execute the search in initialize(), everything
goes well. But if I execute the search by calling the searchFacility()
function from the MFC application, the search is performed, but the
saveSearchResult() never got executed. I put four alert boxes in the
codes to see how program goes. The first two boxes in SearchFacility()
will pop out, but the other two won't.
Here is some of the codes:
<code in cpp file>
//suppose we want to search clinics around a location (lat, lng)
m_mapDlg.m_HtmlCtrl.CallJScript2("SearchFacility",
"l...@lng@clinic");
do
{
m_mapDlg.m_HtmlCtrl.CallJScript("getSearchStatus", &result);
} while (result == "false");
loadSearchResult(".//data//searchresult.txt");
<codes in html file>
var searchDone;
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
...
// Create a search control
searchControl = new google.search.SearchControl();
// Add in local search
localSearch = new google.search.LocalSearch();
var options = new google.search.SearcherOptions();
options.setExpandMode(GSearchControl.EXPAND_MODE_OPEN);
searchControl.addSearcher(localSearch, options);
// Tell the searcher to draw itself and tell it where to attach
searchControl.draw(document.getElementById("searchcontrol"));
// Declare function for using results
searchControl.setSearchCompleteCallback(this,
saveSearchResults);
}
}
function SearchFacility(ar)
{
var a = new VBArray(ar);
var b = a.toArray();
searchDone = "false";
rExp = /(\w|\s)*...@]/ig;
var res = b[0].match(rExp);
lat = parseInt(res[0]);
lng = parseInt(res[1]);
str = lat + "," + lng;
alert(str);
// Set the Local Search center point
localSearch.setCenterPoint(str);
str = String(res[2]);
alert(str);
// Execute an inital search
searchControl.execute(str);
}
//to save the search results in a text file
function saveSearchResults(sc, searcher)
{
alert("start saving result.");
var resultcontent = '';
var resultdiv = document.getElementById('searchresults');
var fso1 = new ActiveXObject("Scripting.FileSystemObject");
var file1 = fso1.CreateTextFile(".//data//searchResult.txt",
true);
file1.WriteLine(searcher.results.length);
for (i=0; i<searcher.results.length; i++)
{
var result = searcher.results[i];
resultcontent += '<p>'+result.title+'<br /
>'+result.streetAddress+'</p>';
message = result.lat + ',' + result.lng + ',' + result.title
+ ',' + result.streetAddress + '\r\n';
file1.WriteLine(message);
}
resultdiv.innerHTML = resultcontent;
file1.Close();
alert("finish saving result.");
searchDone = "true";
}
function getSearchStatus() {
return searchDone;
}
Can anyone give some advices on this? Thanks a lot.
--
You received this message because you are subscribed to the Google Groups
"Google AJAX APIs" 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-ajax-search-api?hl=en.