Add Save my Location - GeoSmartCity-CIP/gsc-client GitHub Wiki
#Add/Save my Location
This module enables a user to save custom locations to their user profile. It relies on a running instance of the gsc_datacatalogue
for persistent data storage. The location is serialized to a GeoJSON string and is stored linked to a registered user account on a remote server so that the persistence may be shared as the user logs into the application from different computers.
API
API is available at GitHub src/location/location.js.
Example
The following example illustrates the capabilities of the location storage feature of the gsc.js library.
// First log in to a user account as all operations require an active user session
gsc.user.login(‘user’, ‘pass’)
.then(function(success) {
// Add a new location to the users’s account
var myLocation = new gsc.location.Location(‘Milan’, 9.1859, 45.4654);
gsc.location.addLocation(myLocation);
// Retrieve saved locations from the user’s account
gsc.location.getLocationList()
.then(function(locationList) {
// Remove the first location from the user’s list of saved locations
var firstEntry = locationList[0];
gsc.location.removeLocation(firstEntry)
.then(function(success) {
// Done
});
|
// Convert the second stored location to GeoJSON
var secondEntry = locationList[1].asGeoJSON();
// Do something with the GeoJSON feature
}, function(err) {
// Handle error
});
}, funcation(err) {
});