SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot moretea's Avatar
    Join Date
    Jun 2004
    Location
    Texas, USA
    Posts
    117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Question Reverse geolocation, parsing JSON in IE9?

    I'm baffled! I'm coding in HTML5 and getting back the geo coordinates with no problems; I set them as cookies for future reference, then pass them to a reverse geolocation server using $.getJSON in jQuery 1.5.1. I have to parse through the results, but I manage to get the user's US state location (which is my goal) in Firefox, but not in IE.

    The JSON appears to be well-formed, and looks like this:
    Code JavaScript:
    {"place_id":"3065317","licence":"Data Copyright OpenStreetMap Contributors, Some Rights Reserved. CC-BY-SA 2.0.","osm_type":"node","osm_id":"356821721","lat":"32.9029017","lon":"-96.5636022","display_name":"Church of the Nazarene, Main Street, Dallas, Texas, 75088, United States of America","address":{"place_of_worship":"Church of the Nazarene","road":"Main Street","city":"Dallas","county":"Dallas","state":"Texas","postcode":"75088","country":"United States of America","country_code":"us"}}

    Here's how I'm parsing it (not elegant I know, and I wouldn't mind suggestions on improvements!):
    Code JavaScript:
        $.getJSON('http://nominatim.openstreetmap.org/reverse?format=json&lat=' + Get_Cookie('Latitude') +'&lon=' + Get_Cookie('Longitude') + '&zoom=18&addressdetails=1',
            function(data) {
                var st;
                $.each(data, function(key,val) {
                    if (key == 'address') {
                        $.each(val, function(subkey,subval) {
                            if (subkey == 'state') {
                                st = subval;
                            };
                        });
                    }
                });
                Set_Cookie('state',st,true,'/');
            });

    Would appreciate any help on this... TIA!

  2. #2
    SitePoint Zealot moretea's Avatar
    Join Date
    Jun 2004
    Location
    Texas, USA
    Posts
    117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Oh, and it does work on Chrome and Safari. I'm finding the problem on IE9; no doubt it exists in earlier versions as well.

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Can you confirm whether IE9 actually gets the state in the st variable, by alerting it on a test page?

    I tried the code from your post and it seems to get the state just find in IE9, so either it's something about my test page, or it's something else other than retrieving the state.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    SitePoint Zealot moretea's Avatar
    Join Date
    Jun 2004
    Location
    Texas, USA
    Posts
    117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Post

    Thanks for checking Paul! It looks as if IE9 is not even making it to the callback function in getJSON, as my alerts never get fired. See below.

    Code:
    $.getJSON('http://nominatim.openstreetmap.org/reverse?format=json&lat=' + Get_Cookie('Latitude') +'&lon=' + Get_Cookie('Longitude') + '&zoom=18&addressdetails=1',
       function(data) {
                     var st;
                     alert('Hello?');
                     $.each(data, function(key,val) {
                           if (key == 'address') {
                                 alert('Address found!');
                                 $.each(val, function(subkey,subval) {
                                     if (subkey == 'state') {
                                           alert('State found! ' + subval);
                                           st = subval;
                                     };
                               });
                         }
                   });
                  $('#details').prepend('Welcome ' + st + ' visitor!');            
                  Set_Cookie('state',st,true,'/');
            });

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by moretea View Post
    Thanks for checking Paul! It looks as if IE9 is not even making it to the callback function in getJSON, as my alerts never get fired.
    It is likely that Internet Explorer is applying aggressive caching? Here's a viable solution to that:
    http://i.justrealized.com/2008/jquer...rnet-explorer/
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    SitePoint Zealot moretea's Avatar
    Join Date
    Jun 2004
    Location
    Texas, USA
    Posts
    117
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What a hoot--I've got that tab open already! Will peruse the article and give it a go. Thanks again, mucho!


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •