Skip to content

Instantly share code, notes, and snippets.

@binarypie
Created June 15, 2010 21:33
Show Gist options
  • Save binarypie/439766 to your computer and use it in GitHub Desktop.
Save binarypie/439766 to your computer and use it in GitHub Desktop.
function getLocation() {
// The static location.
if (typeof widget == 'undefined' || props.staticLocation == true) {
// we don't need to update our location as we are static
if (searchActive == false &&
center_default.lat === props.defaultLatitude &&
center_default.lng === props.defaultLongitude) {
return;
}
center_default.lat = props.defaultLatitude;
center_default.lng = props.defaultLongitude;
createPoint();
return;
}
try {
so = device.getServiceObject("Service.Location", "ILocation");
}
catch (e) {
alert("Can't find GPS service: " + e);
if (!hasTried) {
props.staticLocation = true;
hasTried = true;
getLocation();
}
return;
}
try {
var updateoptions = new Object();
updateoptions.PartialUpdates = false;
updateoptions.UpdateTimeOut = 120000000;
var criteria = new Object();
// criteria.LocationInformationClass = "GenericLocationInfo";
criteria.LocationInformationClass = "BasicLocationInformation";
criteria.Updateoptions = updateoptions;
// var result = so.ILocation.Trace(criteria, callbackLocation);
var result = so.ILocation.GetLocation(criteria, callbackLocation);
var errCode = result.ErrorCode;
if (errCode) {
alert("Can't find current location.");
if (!hasTried) {
props.staticLocation = true;
hasTried = true;
getLocation();
}
}
}
catch (e) {
alert("Can't find GPS signal: " + e);
if (!hasTried) {
props.staticLocation = true;
hasTried = true;
getLocation();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment