Click here to Skip to main content
15,888,216 members
Home / Discussions / JavaScript
   

JavaScript

 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan15-Sep-15 9:09
mveRichard MacCutchan15-Sep-15 9:09 
GeneralRe: Callback is not a function error Pin
MadDashCoder15-Sep-15 10:40
MadDashCoder15-Sep-15 10:40 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan15-Sep-15 10:45
mveRichard MacCutchan15-Sep-15 10:45 
GeneralRe: Callback is not a function error Pin
MadDashCoder15-Sep-15 14:21
MadDashCoder15-Sep-15 14:21 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan15-Sep-15 21:20
mveRichard MacCutchan15-Sep-15 21:20 
GeneralRe: Callback is not a function error Pin
MadDashCoder15-Sep-15 23:29
MadDashCoder15-Sep-15 23:29 
GeneralRe: Callback is not a function error Pin
Richard MacCutchan16-Sep-15 0:01
mveRichard MacCutchan16-Sep-15 0:01 
GeneralRe: Callback is not a function error Pin
MadDashCoder16-Sep-15 9:33
MadDashCoder16-Sep-15 9:33 
Hi Richard, I think I understand why you said I did not initialize the global varibles before calling the GetClosestRestaurant() function. It is because I called it outside of the GetLatLong() function.

However, the same errors are still present after moving GetClosestRestaurant() inside of GetLatLong() and placing it at the very end to ensure all the global variables are initialized.

The following is all I'm trying to do:
JavaScript
Have the user enter into the textboxes his current address, the desired distance from restaurants, and the number of results to return.

Then pass the address which the user had placed in the textbox on my page to a function that will call Google Map API to get the latitude and longitude of the entered address.

Once lat and lng values from Google API are received, call a web service to get a list of restaurants
(which are within the specified distance entered by user) from my database.

I thought about writing this in JQuery but decided against it because I want to get a better grip of raw Javascript. I have modified the code to make it reflect the changes I've made in my projet file. Please take a look at my code below to see if you can spot where my problems lie now. Thanks for helping.
JavaScript
 var _lat, _lng, _location, _distance, _results;
function GetClosestRestaurant(ilocation, idistance, iresults, callback) { 

        _lat = ilocation.lat();
        _lng = ilocation.lng(); 
        var jdata = { lat: _lat, lng: _lng, distance: idistance, results:iresults }; 
        var xhr = new XMLHttpRequest();

        xhr.onreadystatechange = function () {
            if (xhr.readyState < 4) { 
                return;
            }
            if (xhr.status !== 200) { 
                return;
            }
        };

        xhr.open('Get', "http://localhost:21311/myService.asmx/GetClosestPlace", true);
        xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8"); 
        xhr.send(JSON.stringify(jdata));
        callback(xhr.responseText);
    }

    function GetLatLong(addr, callback) {

     _distance = document.getElementById("Distance").value;
     _results = document.getElementById("Results").value;

     var geocoder = new google.maps.Geocoder();
     geocoder.geocode({ 'address': addr }, function (searchResults, searchStatus) {
        _location = searchResults[0].geometry.location;        
        callback(_location, _distance, _results, GetClosestRestaurant);
     });

     GetClosestRestaurant(_location, _distance, _results, DisplayClosestRestaurant); 
    }

    function GetAddress() {
      var address = document.getElementById("Distance").value;
      GetAddress(address, GetClosestRestaurant);
    }

//Inside my page
HTML
<div><input type="button" value="Submit" onclick="GetAddress()"/></div>


modified 16-Sep-15 18:24pm.

GeneralRe: Callback is not a function error Pin
Richard MacCutchan16-Sep-15 21:26
mveRichard MacCutchan16-Sep-15 21:26 
QuestionJavascript and JQuery? Pin
Member 119720439-Sep-15 8:35
Member 119720439-Sep-15 8:35 
AnswerRe: Javascript and JQuery? Pin
Blikkies10-Sep-15 18:47
professionalBlikkies10-Sep-15 18:47 
AnswerRe: Javascript and JQuery? Pin
Member 1201497027-Sep-15 6:56
Member 1201497027-Sep-15 6:56 
AnswerRe: Javascript and JQuery? Pin
aarif moh shaikh1-Oct-15 0:32
professionalaarif moh shaikh1-Oct-15 0:32 
QuestionJavaScript runtime error: Unable to set property 'value' of undefined or null reference Pin
Rajesh_19808-Sep-15 10:00
Rajesh_19808-Sep-15 10:00 
AnswerRe: JavaScript runtime error: Unable to set property 'value' of undefined or null reference Pin
Richard Deeming14-Sep-15 3:41
mveRichard Deeming14-Sep-15 3:41 
QuestionAutomated Javascript Pin
Member 119664927-Sep-15 16:10
Member 119664927-Sep-15 16:10 
AnswerRe: Automated Javascript Pin
Peter Leow7-Sep-15 17:30
professionalPeter Leow7-Sep-15 17:30 
QuestionHow do I modify existing code to also hide/show controls under Justification for Request section? Pin
samflex4-Sep-15 7:33
samflex4-Sep-15 7:33 
QuestionGet Axis interval Pin
NJdotnetdev3-Sep-15 4:05
NJdotnetdev3-Sep-15 4:05 
QuestionRe: Get Axis interval Pin
Richard MacCutchan3-Sep-15 5:38
mveRichard MacCutchan3-Sep-15 5:38 
AnswerRe: Get Axis interval Pin
NJdotnetdev3-Sep-15 5:53
NJdotnetdev3-Sep-15 5:53 
GeneralRe: Get Axis interval Pin
F-ES Sitecore3-Sep-15 6:06
professionalF-ES Sitecore3-Sep-15 6:06 
GeneralRe: Get Axis interval Pin
NJdotnetdev3-Sep-15 7:19
NJdotnetdev3-Sep-15 7:19 
QuestionExport html page with icons (font awesome) as image using javascript ? Pin
Mogli_001-Sep-15 20:03
Mogli_001-Sep-15 20:03 
AnswerMessage Closed Pin
10-Feb-22 5:12
Front-end.codes10-Feb-22 5:12 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.