|
|
(11 intermediate revisions by 2 users not shown) |
Line 1: |
Line 1: |
| NSB/App Studio programs run within a special version of a web browser.
| | AppStudio programs can use the capabilities of the web browser. |
| As a result, they can inherit a lot of the properties of the environment they run in. | | As a result, they can inherit a lot of the properties of the environment they run in. |
| You can access these properties from within your app. | | You can access these properties from within your app. |
|
| |
|
| It is not a complete list: there are additional items in the full HTML documentation. In addition, some browsers may have additional members not shown here. | | It is not a complete list: there are additional items in the full HTML documentation. In addition, some browsers may have additional properties not shown here. |
|
| |
|
| navigator.geolocation.getCurrentPosition(<i>showMap</i>)
| | On iOS, In Settings...Privacy...Location Sevices, make sure that Safari is set to "While using the App". It will then request permission when geolocation is used. The app needs to be loaded to your device using https: if you load using http, the OS will not allow you to use geolocation. |
|
| |
|
| <i>showMap</i> is the name of a function in your program, which will be called by the above statement. It is passed a single parameter: an object with the following fields: | | navigator.geolocation.getCurrentPosition(<i>successFunction</i>[, ''errorFunction''[, ''parameters'']]) |
|
| |
|
| '''geolocation object members''' | | <i>successFunction</i>(required) is the name of a function in your program, which will be called by the above statement. It is passed a single parameter: an object with the Geolocation Object Members: |
| | |
| | <i>errorFunction</i> (optional) is the name of the function to call if the operation fails. It returns (code, message). |
| | |
| | <i>parameters</i> (optional) is a PositionOptions object (see below) with information how the call should work. |
| | |
| | '''Geolocation Object Members''' |
|
| |
|
| {| class="wikitable" | | {| class="wikitable" |
Line 16: |
Line 22: |
| |- | | |- |
| |location.coords.latitude || The current latitude of the device. GPS required. | | |location.coords.latitude || The current latitude of the device. GPS required. |
| | |- |
| | |location.coords.altitude|| The height of the location. GPS required. |
| |- | | |- |
| |location.coords.accuracy || The accuracy of the location. GPS required. | | |location.coords.accuracy || The accuracy of the location. GPS required. |
| | |- |
| | |location.coords.altitudeAccuracy || The accuracy of the altitude. GPS required. |
| | |- |
| | |location.coords.heading|| Degrees clockwise from North. GPS required. |
| | |- |
| | |location.coords.speed|| Speed, meters per second. GPS required. |
| | |- |
| | |location.coords.timestamp || time and date of the observation. GPS required. |
| | |} |
| | |
| | '''PositionOptions Object Members''' |
| | |
| | {| class="wikitable" |
| | |- |
| | |enableHighAccuracy || True/False. May take a bit longer. |
| | |- |
| | |timeout || Milliseconds to wait for the result. |
| | |- |
| | |maximumAge || Use a cached result if within the specified number of milliseconds. |
| |} | | |} |
|
| |
|
Line 24: |
Line 51: |
| == Example == | | == Example == |
|
| |
|
| <pre> | | <tabber> |
| | JavaScript= |
| | <syntaxhighlight lang="JavaScript"> |
| | // Geolocation |
| | |
| | function handler(location) { |
| | var s; |
| | NSB.Print("Longitude: " + location.coords.longitude); |
| | NSB.Print("Latitude: " + location.coords.latitude); |
| | NSB.Print("Accuracy: " + location.coords.accuracy); |
| | s = "<img src='http://maps.google.com/maps/api/staticmap?center="; |
| | s += location.coords.latitude + "," + location.coords.longitude; |
| | s += "&zoom=14&size=300x200&maptype=roadmap'>"; |
| | NSB.Print(s); |
| | |
| | navigator.geolocation.getCurrentPosition(handler); |
| | } |
| | </syntaxhighlight> |
| | |-| |
| | BASIC= |
| | <syntaxhighlight lang="vb.net"> |
| REM Geolocation | | REM Geolocation |
| Function handler(location) | | Function handler(location) |
Line 33: |
Line 80: |
| s = "<img src='http://maps.google.com/maps/api/staticmap?center=" & _ | | s = "<img src='http://maps.google.com/maps/api/staticmap?center=" & _ |
| location.coords.latitude & "," & location.coords.longitude & _ | | location.coords.latitude & "," & location.coords.longitude & _ |
| "&zoom=14&size=300x200&maptype=roadmap&sensor=false'>" | | "&zoom=14&size=300x200&maptype=roadmap'>" |
| print s | | print s |
| End Function | | End Function |
|
| |
|
| navigator.geolocation.getCurrentPosition(handler); | | navigator.geolocation.getCurrentPosition(handler); |
| </pre> | | </syntaxhighlight> |
| | | </tabber> |
| == Example (JavaScript) ==
| |
| <pre>
| |
| // Geolocation
| |
| | |
| function handler(location) {
| |
| var s;
| |
| NSB.Print("Longitude: " + location.coords.longitude);
| |
| NSB.Print("Latitude: " + location.coords.latitude);
| |
| NSB.Print("Accuracy: " + location.coords.accuracy);
| |
| s = "<img src='http://maps.google.com/maps/api/staticmap?center=" + location.coords.latitude + "," + location.coords.longitude + "&zoom=14&size=300x200&maptype=roadmap&sensor=false'>";
| |
| NSB.Print(s);
| |
| }
| |
| | |
| navigator.geolocation.getCurrentPosition(handler);
| |
| </pre> | |
|
| |
|
| == Output == | | == Output == |
AppStudio programs can use the capabilities of the web browser.
As a result, they can inherit a lot of the properties of the environment they run in.
You can access these properties from within your app.
It is not a complete list: there are additional items in the full HTML documentation. In addition, some browsers may have additional properties not shown here.
On iOS, In Settings...Privacy...Location Sevices, make sure that Safari is set to "While using the App". It will then request permission when geolocation is used. The app needs to be loaded to your device using https: if you load using http, the OS will not allow you to use geolocation.
navigator.geolocation.getCurrentPosition(successFunction[, errorFunction[, parameters]])
successFunction(required) is the name of a function in your program, which will be called by the above statement. It is passed a single parameter: an object with the Geolocation Object Members:
errorFunction (optional) is the name of the function to call if the operation fails. It returns (code, message).
parameters (optional) is a PositionOptions object (see below) with information how the call should work.
Geolocation Object Members
location.coords.longitude |
The current longitude of the device. GPS required.
|
location.coords.latitude |
The current latitude of the device. GPS required.
|
location.coords.altitude |
The height of the location. GPS required.
|
location.coords.accuracy |
The accuracy of the location. GPS required.
|
location.coords.altitudeAccuracy |
The accuracy of the altitude. GPS required.
|
location.coords.heading |
Degrees clockwise from North. GPS required.
|
location.coords.speed |
Speed, meters per second. GPS required.
|
location.coords.timestamp |
time and date of the observation. GPS required.
|
PositionOptions Object Members
enableHighAccuracy |
True/False. May take a bit longer.
|
timeout |
Milliseconds to wait for the result.
|
maximumAge |
Use a cached result if within the specified number of milliseconds.
|
For more information on Google Maps, read http://code.google.com/apis/maps/documentation/staticmaps/.
Example
// Geolocation
function handler(location) {
var s;
NSB.Print("Longitude: " + location.coords.longitude);
NSB.Print("Latitude: " + location.coords.latitude);
NSB.Print("Accuracy: " + location.coords.accuracy);
s = "<img src='http://maps.google.com/maps/api/staticmap?center=";
s += location.coords.latitude + "," + location.coords.longitude;
s += "&zoom=14&size=300x200&maptype=roadmap'>";
NSB.Print(s);
navigator.geolocation.getCurrentPosition(handler);
}
REM Geolocation
Function handler(location)
Dim s
Print "Longitude: " + location.coords.longitude
Print "Latitude: " + location.coords.latitude
Print "Accuracy: " + location.coords.accuracy
s = "<img src='http://maps.google.com/maps/api/staticmap?center=" & _
location.coords.latitude & "," & location.coords.longitude & _
"&zoom=14&size=300x200&maptype=roadmap'>"
print s
End Function
navigator.geolocation.getCurrentPosition(handler);
Output
Longitude: -79.2098782
Latitude: 43.73776441
Accuracy: 100
(map of current location)