Created
June 22, 2013 19:11
-
-
Save timanglade/5842186 to your computer and use it in GitHub Desktop.
Geolocation Examples
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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… | |
); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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