I have 2 js files.  1 is the jquery jmaps plugin (jmaps.js) (basically
porting the google maps api to make creating google maps easier) and
then the other file is all the actionable code (agency.js) to do
stuff.

I've been extending the plugin to add some features the original
author did not put in the plugin, but am having an issue with the
callback function from google.  Take a look:

from agency.js.....

 for (i = 0; i < officeArray.length; i++) {
                var lat1 = officeArray[i][0];
                var lng1 = officeArray[i][1];

                // Radial search
                res[i] = LatLon.distHaversine(lat1.parseDeg(),
lng1.parseDeg(), lat2.parseDeg(), lng2.parseDeg()).toPrecision(4) + '
Miles';

                // If it is within range, then grab it's address and
place a marker.
                if (parseFloat(res[i]) <= maxRadius) {

                    // Check to see if we should add streetview --
THIS IS THE FUNCTION I'M HAVING ISSUES WITH

                    $jmap2.jmap("checkForStreetView", {lat: lat1, lng:
lng1});

                    var htmlType = $j('#directions p').text();

                    alert(htmlType); // Whenever this alert goes out,
the first iteration is blank and the second alert's value is the
actual value of the first...clearly a callback related issue.

                    //$j('#directions p').text('');

            } // End for loop


from jmaps.js.............

// this is the function I extended:


    $.jmap.checkForStreetView = function(options, callback)
    {
        var codeNum = 0;
        options = $.extend({}, $.jmap.JStreetViewDefaults, options);
        var location = new GLatLng(options.lat, options.lng);
        panoClient = new GStreetviewClient();
        panoClient.getNearestPanorama(location, processReturnedData);

        function processReturnedData(panoData){

            if (panoData.code != 200) {
                    $('#directions').append('<p>'+panoData.code+'</
p>');
                        return;
                    }
                    else{
                        $('#directions').append('<p>'+panoData.code+'</
p>');
                        return;
                    }
                }

        if (typeof callback == 'function')
               return callback(panoData, options);
    } // End checkForStreetView



The issue is with the processReturnedData() function.  As you can see
it is a callback function for the 'getNearestPanorama' method of the
GStreetviewClient object.  The code property is just a response code
from google's server.  Ultimately I would like the checkForStreetView
function to return its callee the value of panoData, but for the time
being I'm just having it append it's value to a paragraph inside a
div.

However, the value, in the above for loop, is always one value behind
when I trigger the alert.  Any insight on this?  I seem to have tried
all kinds of things like wrapping the functions, etc. but nothing
seemed to work.

I would be happy with just appending the text and using it later for
my other code down the line, but is there any way to have the
checkForStreetView function return the panoData.code value?  That's
really what I need access to.

Thanks a million in advance.

Reply via email to