Skip to main content
Inspiring
July 18, 2013
Answered

Json/Jquery Variable problem

I'm having an issue in building a yardsale map using jquery google map,while also providing some weather via a Json call to yahoo weather.

I'm placing map markers via a Json call of adresses. Placing the marker (if the adress is found) it builds the infowindow with info I provide (from the yardsale Json call). That works. I'm trying to add some weather data in each info window. I can get the data I need, and Assign it to a varaible, but when I try to bring it into the piece that places the info in the window, It comes as undefined.

I've tried placing the varible as a global variable outside the function (under the doc ready call)?

Can any body show/tell me how to get the vaiable to work (and why so I don't make the same mistake)

here is the code below:

$(document).ready(function() {

  var val

  var address="Boston, Mass"

  var currdate

 

  //weatherwidget (address)

 

          $('#map_canvas').gmap('search', { 'address': 'Boston, Mass' }, function(results,isFound) {

            if (isFound)

            {

                      $('#map_canvas').gmap('get','map').panTo(results[0].geometry.location);

                      $('#map_canvas').gmap('option', 'zoom', 10);   

            }

     });

 

 

                    $.getJSON('Yardsaleagate.json', function(yard_data)

                                        {

                                                  $.each(yard_data.yardsales, function{

                                                            var val = this.address

                                                            var key = this.stuff

 

                                                            setTimeout(function(){

                                                                      $('#map_canvas').gmap('search', { 'address': val }, function(results,isFound) {

                                                    if (isFound)

                                                    {

                                                              $.getJSON('http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20weather.forecast%20where%20location%20in%20(%0A%20%20select%20id%20from%20weather.search%20where%20query%3D%22'+address+'%22%0A)%20limit%201&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=?',function(data)

                                                                                {

                                                                                var currdate = (data.query.results.channel.item.forecast[0].date)

                                                                                console.log(currdate)

                                                                                })

                                                              $('#map_canvas').gmap('addMarker', { 'position': results[0].geometry.location, 'description': key, icon: "map-icons/pins/32/pin_ys.png",'animation': google.maps.Animation.DROP, 'info': val}).mouseover(function(){ weatherlocation(val)}).click(function() {

                var infocontent = "<div class='info'>"+ currdate +"<div class='header'><h3>"+ val+" </h3></div> <p>"+this.description+"</><div>"

                                                        $('#map_canvas').gmap('openInfoWindow', { 'content':  infocontent, 'maxWidth': 300 }, this);

                                                                    });

                                                    }

                                                            })

                                                            }, i*700);

                                           });

                                        

                                        });

});

This topic is closed to new replies. Start a new post to keep the conversation going.
JonnyDLCorrect answer
Inspiring
July 18, 2013

Figured it out (or a solution that works) move the infowindow build into the weather call infowindow will stll build

2 replies

JonnyDLAuthorCorrect answer
Inspiring
July 18, 2013

Figured it out (or a solution that works) move the infowindow build into the weather call infowindow will stll build

Translate
sudarshan.t
Inspiring
July 18, 2013

Moved thread from Dreamweaver CC to Developing Server-Side Applications in Dreamweaver for better responses.

Translate