Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm using a geocoding plugin (Leafet.GeoSearch) on a map and I'd like the results, being the LatLng point coordinates, etc available as a parameter for GeoServer cql filtered calls.

It doesn't seem to be as easy as I thought it would be. I've read several forums which claim data can't be persistent between pages/files. Could someone enlighten me and or make a suggestion please. I'm in over my head.

here is a snippet of the code that has the array I'd like available

ParseJSON : function(data) {
        if (data.resourceSets.length == 0 || data.resourceSets[0].resources.length == 0)
            return [];

        var results = [];
        for (var i = 0; i < data.resourceSets[0].resources.length; i++)
            results.push(new L.GeoSearch.Result(
                data.resourceSets[0].resources[i].point.coordinates[1], 
                data.resourceSets[0].resources[i].point.coordinates[0], 
                data.resourceSets[0].resources[i].address.formattedAddress));
        return results;
    }
share|improve this question
    
sorry about the title but I'm a javascript newb. I was hoping this would be an easy answer, but as I continue research there seems to be some disparity among suggested methods. All of which I haven't a clue how to implement. hopefully someone with experience will have an idea what I want and edit this question. –  geomajor56 Jan 25 '13 at 12:22
    
Are you asking to get the data out of the function and use it somewhere else on the page? In which case @geomajor56's answer works. If you want to use it in another page, or use it in a different program that is going to be very tricky as JavaScript sandboxes all of the web pages to prevent this, depending on what exactly your trying to do you're most likely going to want to get the data closer to where you're going to use it. –  Calvin Jan 26 '13 at 14:17
    
This should be a comment, not an answer. Also, OP answered his own question so it's probably best to delete this. –  Derek Swingley Jan 26 '13 at 17:44
add comment

1 Answer

Got a solution from Boston Python Users Group IRC.

"all global variables are implicitly attached to the window object — if you attach a variable to the window object, you'll be able to access it from anywhere". example window.myArray = the_object

for (var i = 0; i < data.resourceSets[0].resources.length; i++)
        results.push(new L.GeoSearch.Result(
            data.resourceSets[0].resources[i].point.coordinates[1], 
            data.resourceSets[0].resources[i].point.coordinates[0], 
            data.resourceSets[0].resources[i].address.formattedAddress));
            ***window.thisAddress = results;*** // this is all I needed       
    return results;
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.