Wednesday, 27 April 2011

Get your current GPS location

This is a very basic webOS app that shows your current GPS location.

At times, when indoor, the GPS will not give an accurate geolocation, so my suspect that this issue has been embedded in the framework and not the GPS. Perhaps, this is the issue that was reported earlier and was supposedly fixed in webOS 2.0 and webOS 2.1.

This is the value that I am getting and similar to Foursquare, Gowalla, etc.
Latitude = 392.584986 (this is the culprit)
Longitude = 174.865368 (this is correct)



assistant.js:
WAIAssistant.prototype.setup = function() {
/* this function is for setup tasks that have to happen when the scene is first created */
/* use Mojo.View.render to render view templates and add them to the scene, if needed */
/* setup widgets here */
/* add event handlers to listen to events from widgets */

// Set up Spinner for the scrim when getting a GPS fix
this.controller.setupWidget("divSpinner",
{ spinnerSize : "large" }, { spinning : true });

this.controller.setupWidget("txtLatitude",
{ maxLength : 20 }, this.txtLatitudeModel);
this.controller.setupWidget("txtLongitude",
{ maxLength : 20 }, this.txtLongitudeModel);

this.controller.setupWidget("btnWAI", { },
{ label : "Where Am I" } );

Mojo.Event.listen(this.controller.get("btnWAI"),
Mojo.Event.tap, this.wai.bind(this));
};

WAIAssistant.prototype.wai = function() {

$("divScrim").show();
var gps_address, gps_latitude, gps_longitude;

this.controller.serviceRequest("palm://com.palm.location", {
method : "getCurrentPosition",
parameters : {maximumAge : 60},
onSuccess : function(inResponse) {
$("divScrim").hide();
switch (inResponse.errorCode) {
case 0:

gps_latitude = inResponse.latitude;
gps_longitude = inResponse.longitude;
this.controller.get('txtLatitude').mojo.setValue (gps_latitude);
this.controller.get('txtLongitude').mojo.setValue (gps_longitude);

this.controller.serviceRequest("palm://com.palm.applicationManager", {
method: "open",
parameters: {
id: "com.palm.app.maps",
params: {
location: {lat: gps_latitude, lng: gps_longitude}
}
}
});

break;

case 1: case 2: case 3:
Mojo.Controller.errorDialog(
"GPS fix timeout - you will need a clear sky for GPS fix."
);
break;

case 5: case 6:
Mojo.Controller.errorDialog(
"GPS fix cannot be activated - Location Service is off or not accepted the terms of use."
);
break;

case 7: case 8:
Mojo.Controller.errorDialog(
"GPS fix is underway - pending request or temporarily blacklisted."
);
break;
}
}.bind(this),
onFailure : function(inResponse) {
$("divScrim").hide();
switch (inResponse.errorCode) {
case 1: case 2: case 3:
Mojo.Controller.errorDialog(
"GPS fix timeout - you will need a clear sky for GPS fix."
);
break;

case 5: case 6:
Mojo.Controller.errorDialog(
"GPS fix cannot be activated - Location Service is off or not accepted the terms of use."
);
break;

case 7: case 8:
Mojo.Controller.errorDialog(
"GPS fix is underway - pending request or temporarily blacklisted."
);
break;
}
}
});

};

No comments:

Post a Comment