alert()
現在、プログラムは動作していますが、関数で使用している関数のために、インターフェイスが煩わしいですgetData()
!! この行を関数から削除すると、getData()
プログラム全体が失敗します。何が問題なのかわかりませんか?誰かがそのようなプロセスを行うためのより良い考えを持っていますか?
ここで作成しようとしているプログラムは、ユーザーが現在の住所から50 km以内にあるレストランを見つけられるようにすることを目的としています。すでにさまざまな場所の住所を収集し、データベースに記録しています。
initialize()
HTML本文が読み込まれるときに呼び出される関数。HTML本文の最初の行で、レストランデータはPHPを使用してMySQLから抽出され、JavaScript配列jsres_add、jsres_id、jsres_name、jsnuに出力されるため、JavaScriptコードで使用できます。*以下のようなJavaScriptコードは.jsファイルで区切られていることに注意してください
var geocoder, location1, location2, gDir, oMap, jsnu, arraynu, address2;
jsres_add = new Array();
jsres_id = new Array();
jsres_name = new Array();
function initialize() {
geocoder = new GClientGeocoder();
gDir = new GDirections();
GEvent.addListener(gDir, "load", function() {
var drivingDistanceMiles = gDir.getDistance().meters / 1609.344;
var drivingDistanceKilometers = gDir.getDistance().meters / 1000;
if (drivingDistanceKilometers < 50){
// function to save search result within 50km into database using ajax
saveSearchResult(jsres_id[arraynu],jsres_name[arraynu],drivingDistanceKilometers);
}
});
}
function getData() {
emptytable(); //function to empty search result table using ajax
//jsnu is the number of the restaurants data found in database
for (var ii = 0; ii < jsnu; ii++) {
arraynu = ii;
address2 = jsres_add[ii];
showLocation();
alert("done!");
}
showResults(); //function to print out the search result from database into html body using ajax
}
function showLocation() {
geocoder.getLocations(document.forms[0].address1.value, function (response) {
if (!response || response.Status.code != 200){
alert("Sorry, we were unable to geocode your address");
}else{
location1 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
geocoder.getLocations(address2, function (response) {
if (!response || response.Status.code != 200){
alert("Sorry, we were unable to geocode the second address");
}else{
location2 = {lat: response.Placemark[0].Point.coordinates[1], lon: response.Placemark[0].Point.coordinates[0], address: response.Placemark[0].address};
gDir.load('from: ' + location1.address + ' to: ' + location2.address);
}
});
}
});
}