Skip to content

Instantly share code, notes, and snippets.

@iantearle iantearle/alloy.js
Created Sep 9, 2013

Embed
What would you like to do?
BasicGeo where its not starting location services on iOS7 with v0.86
var geo = require('bencoding.basicgeo');
Alloy.Globals.geoCurrent = geo.createCurrentGeolocation();
Alloy.Globals.geoCoder = geo.createGeocoder();
Alloy.Globals.helpers = geo.createHelpers();
function CurrentPositionCallback(e) {
if(!alreadyCalled) {
$.loading.show('Finding...', true);
if(e === null) {
var a = Titanium.UI.createAlertDialog({title:'Heritage'});
a.setMessage(L('location_error'));
}
if(e.success) {
var position = {};
position.latitude = e.coords.latitude;
position.longitude = e.coords.longitude;
Ti.App.Properties.setObject('position', position);
Ti.API.info(propertiesFetchLocation(e.coords.latitude, e.coords.longitude));
$.loading.hide();
$.searchField.value = '';
}
var test = JSON.stringify(e);
Ti.API.info("Current Results stringified" + test);
alreadyCalled = true;
}
}
function forwardGeoCallback(e) {
$.loading.show('Finding...', true);
if(e.success) {
var test = JSON.stringify(e);
Ti.API.info("Forward Results stringified" + test);
Ti.API.info(propertiesFetchLocation(e.places[0].latitude, e.places[0].longitude));
$.loading.hide();
Ti.API.info("Places found = " + e.placeCount);
for (var iLoop=0;iLoop<e.placeCount;iLoop++){
Ti.API.info("Showing Place At Index " + iLoop);
Ti.API.info(e.places[iLoop]);
}
$.searchField.value = '';
}
}
/* Start DB Collection */
function propertiesFetchLocation(latitude, longitude) {
properties.fetch({
query: 'SELECT * FROM properties WHERE distance(latitude, longitude, '+ latitude +', '+ longitude +') < 20 ORDER BY distance(latitude, longitude, '+ latitude +', '+ longitude +') ASC LIMIT 50'
});
return properties.length;
}
function propertiesFetchTitle(title) {
var position = Ti.App.Properties.getObject('position');
properties.fetch({
query: 'SELECT * FROM properties WHERE REPLACE(UPPER(title), "/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g", "") LIKE "%' + title.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g, "") + '%" ORDER BY distance(latitude, longitude, '+ position.latitude +', '+ position.longitude +') ASC'
});
return properties.length;
}
/* Get our current location */
function resultsCallback(e){
Ti.API.info("Did it work? " + e.success);
if(e.success){
Ti.API.info("It worked");
}
var test = JSON.stringify(e);
Ti.API.info("Results stringified " + test + ' ' + e.places[0].countryCode);
};
Alloy.Globals.geoCurrent.getCurrentPlace(resultsCallback);
Alloy.Globals.geoCurrent.getCurrentPosition(CurrentPositionCallback);
Alloy.createController('home').getView().open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.