-
Notifications
You must be signed in to change notification settings - Fork 16
Examples
You can see an example of use in the CollabMaps applicaiton
In order to get a reference to the API, you will have to discover the API. You can use the dashboard to allow the user pick the service for you, but you can also do this manually in code (see the API description for the dashboard use).
##Service Discovery This is the list of URIs used to declare this API's features, for use in the widget config.xml and as identifier for service type in service discovery functionality. For each URI, the list of functions covered is provided.
webinos.discovery.findServices(new ServiceType
('http://www.w3.org/ns/api-perms/geolocation'), {onFound:function (service) {
//Stores the Service in a local variable
foundService = service
}
From this point we will refer to the found service as if it was stored in the foundService variable.
##Bind Before using a service, you need to bind to it. Binding is similar on all services. The following code shows how to bind to the Media Content API. Bind to the found and select a service and use. This is required to make calls possible on the webinos service that we created.
geoLocationService.bindService({onBind: function (service) {
document.getElementById('position').innerHTML = "bound Geolocation service";
}
Request a position. Accept positions that is not greater than 10 minutes. If the user agent does not have a fresh enough cached position object, it will automatically acquire a new one. Get positions for latitude, longitude, altitude, accuracy, altitude accuracy, heading, speed and with timestamp.
function handle_geolocation_query(position)
{
var image_url = "http://maps.google.com/maps/api/staticmap?sensor=false¢er=" +
position.coords.latitude + "," +
position.coords.longitude +
"&zoom=14&size=400x400&markers=color:blue|label:S|" +
position.coords.latitude + ',' + position.coords.longitude;
var posdata = "<table>";
posdata += "<tr><td>latitude</td><td>" + position.coords.latitude + "</td></tr>";
posdata += "<tr><td>longitude</td><td>" + position.coords.longitude + "</td></tr>";
posdata += "<tr><td>altitude</td><td>" + position.coords.altitude + "</td></tr>";
posdata += "<tr><td>accuracy</td><td>" + position.coords.accuracy + "</td></tr>";
posdata += "<tr><td>altitudeAccuracy</td><td>" + position.coords.altitudeAccuracy + "</td></tr>";
posdata += "<tr><td>heading</td><td>" + position.coords.heading + "</td></tr>";
posdata += "<tr><td>speed</td><td>" + position.coords.speed + "</td></tr>";
var d = new Date(position.timestamp); // DOMtimestamp is milliseconds since the start of the Unix Epoch
posdata += "<tr><td>timestamp</td><td>" + d.toLocaleString() + "</td></tr>";
posdata += "</table>";
document.getElementById('position').innerHTML = posdata;
jQuery("#map").remove();
jQuery("#mapPlaceHolder").append(
jQuery(document.createElement("img")).attr("src", image_url).attr('id','map')
);
}
Initiate a watch to retrieve the position not more than 10 minutes of age. Get the fresh data and if there is a timeout then show the last position.
function initiate_watch() {
var PositionOptions = {};
if (document.getElementById('acc_high').checked) PositionOptions.enableHighAccuracy = true;
PositionOptions.maximumAge = document.getElementById('freshness').value
PositionOptions.timeout = document.getElementById('timeout').value
document.getElementById('debug').innerHTML = JSON.stringify(PositionOptions); // for debug
watchId = geoLocationService.watchPosition(handle_geolocation_query, handle_errors, PositionOptions);
}
Clears the particular watchId of the Geolocation.
function clear_watch() {
geoLocationService.clearWatch(watchId); // webinos rpc geolocation:
}