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);