Skip to content

Instantly share code, notes, and snippets.

@timanglade
Created June 22, 2013 19:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timanglade/5842186 to your computer and use it in GitHub Desktop.
Save timanglade/5842186 to your computer and use it in GitHub Desktop.
Geolocation Examples
var apigee = new Usergrid.Client({
orgName:'YOUR APIGEE.COM USERNAME',
appName:'sandbox'
});
navigator.geolocation.getCurrentPosition(locationAcquired);
function locationAcquired (whatever) {
new_book = { "title":$("#title-field").val(),
"author":$("#author-field").val(),
"location": {
"latitude":whatever.coords.latitude,
"longitude":whatever.coords.longitude
} };
my_books.addEntity(new_book, function (error, response) {
if (error) {
alert('write failed');
} else {
$("#title-field").val(""), $("#author-field").val("");
loadBooks();
history.back();
}
});
}
var apigee = new Usergrid.Client({
orgName:'YOUR APIGEE.COM USERNAME',
appName:'sandbox'
});
navigator.geolocation.getCurrentPosition(locationAcquired);
function locationAcquired (whatever) {
lat = whatever.coords.latitude;
long = whatever.coords.longitude;
my_ql = 'location within 15000 of'+lat+','+long;
var my_books = new Usergrid.Collection( { "client":apigee, "type":"books", "qs":{"ql":my_ql} } );
my_books.fetch(
// doing whatever I need to do…
);
}
navigator.geolocation.getCurrentPosition(locationAcquired);
function locationAcquired (whatever) {
infinite_jest = client.getEntity({"type":"books", "name":"infinitejest"})
infinite_jest.set("location",{"latitude":whatever.coords.latitude, "longitude":whatever.coords.longitude});
infinite_jest.save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment