वर्तमान में प्रोग्राम काम कर रहा है, लेकिन इंटरफ़ेस परेशान है कि alert()
फ़ंक्शन के कारण मैं getData()
फ़ंक्शन में उपयोग कर रहा हूं !! और जब मैं getData()
फ़ंक्शन से इस पंक्ति को हटाता हूं तो पूरा प्रोग्राम गलत हो जाता है !! मुझे नहीं पता कि समस्या क्या है? खुराक किसी को ऐसी प्रक्रिया करने का बेहतर विचार है?Google मानचित्र API का उपयोग करके एक क्लिक से किसी स्थान से विभिन्न स्थानों पर दूरी कैसे प्राप्त करें?
जिस प्रोग्राम को मैं यहां बनाने की कोशिश कर रहा हूं, वह उपयोगकर्ताओं को अपने वर्तमान पते से 50 किमी के भीतर रेस्तरां खोजने में मदद करने का लक्ष्य रखता है, मैंने पहले से ही विभिन्न स्थान पते एकत्र किए हैं और इसे डेटाबेस में रिकॉर्ड किया है।
initialize()
समारोह जब HTML बॉडी लोड किए गए हैं कहा जाता है, HTML बॉडी रेस्टोरेंट डेटा MySQL से निकालने PHP का उपयोग करें जो JavaScript विन्यास में, डेटा प्रिंट होगा किया जाएगा के पहले लाइनों में jsres_add, jsres_id, jsres_name और jsnu तो मैं उपयोग कर सकते हैं उन्हें जावास्क्रिप्ट कोड में। * नोटिस कृपया 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);
}
});
}
});
}
उपयोग करने के लिए दुर्भाग्य से, यह काम नहीं किया अपने कोड
फिर से लिखने !! लेकिन जैसा कि आपने कहा है कि यह एक समय की समस्या है, मुझे नहीं पता कि किसी प्रकार के ईवेंट हैंडलर एडलिस्टर का उपयोग करना संभव है या नहीं? –
यदि आप http://jsfiddle.net/ सेट अप कर सकते हैं तो यह आपकी सहायता करने के लिए आसान होगा। क्या आप? –
मैंने कार्यक्रम को जितना सरल बनाया उतना छोटा कर दिया है; इसलिए हर कोई आसानी से समस्या देख सकता है, मैंने http://www.jsfiddle.net पर साझा करने से पहले अपने लैपटॉप पर प्रोग्राम का परीक्षण किया है और यह काम कर रहा था, यहां यह http: // jsfiddle है।नेट/ibrahim_zahrani/zuYXS/6/ –