views:

32

answers:

1

I am writing an app for the iphone that fetches weather information based on location. The weather feed works fine for a set location. I have created a parser that fetches gps coordinates based on a programmed called instamapper which posts coordinates online in csv format. I can execute the code fine in IE within a HTML file and see my results. However, as the iphone uses Safari I want to see what my output is. When I run the code in Safari nothing happens, at at least it does and I don't get any output. How can I see my output?

function fetchgps(callback) {
  var url = "http://www.instamapper.com/api?action=getPositions&key=584014439054448247";

  var myRequest = new XMLHttpRequest();
  myRequest.onreadystatechange = function(e) {gps_xml_loaded(event, myRequest, callback);}
  myRequest.open("GET", url);
  myRequest.setRequestHeader("Cache-Control", "no-cache");
  myRequest.setRequestHeader("wx", "385");
  myRequest.send(null);

  return myRequest;
}

function gps_xml_loaded(event, this_request, callback) {
  if (this_request.readyState == 4) {
    if (this_request.status == 200) {
      var obj = {error:false, errorString:null}
      var data = this_request.responseText;
      if (data == null) {
        callback(constructError("no <data>"));
        return;
      }

      collected=data.split(",");   //parses the data delimited by comma and put data into array
      obj.latitude = collected[3];
      obj.longitude = collected[4];
      callback(obj);
    }
    else {
      callback ({error:true, errorString:"Not Ready"}); //Could be any number of things..
    }
  }
}

function dealwithgps(obj) {
  if (obj.error == false) {
    lat = obj.latitude;
    lon = obj.longitude;
    document.write("Latitude "+lat);
    document.write("Longitude "+lon); 
  }
  else {
    document.write("error detected");
  }
}

fetchgps(dealwithgps);
A: 
console.log('output string' + orVariable);

that will log to the console (cmd+alt+i to open the console)
works in firefox too with the firebug extension

pferdefleisch
I am using a windows machine...don't think there is a cmd key.
cameron213
oopsie, my bad. This is coming from a Mac but I have used it on windows and it is pretty close to the same... Open your preferences for the browser. Go the advanced tab or button. Check the choice to Show Develop in Menu bar. Click on your new choice in the menubar, "Develop" and go to "Show Web Inspector". After it is open, go to Console and you should see your console.log("stufffff") output. You can also use the console to interact with your page and fire off any functions that you have available in the global scope. I hope this works! Console is great.
pferdefleisch