[View] [Edit] [Lock] [References] [Attachments] [History] [Home] [Changes] [Search] [Help]
api[www,Geolocation] code
NativeObject
subclass: #GeolocationObject
category: #Geolocation!
GeolocationObject comment: '
Provides an API that provides scripted access to geographical location information associated with the hosting device.
http://www.w3.org/TR/geolocation-API/
@2013 Alejandro Reimondo [email protected]
The Geolocation API defines a high-level interface to location information associated only with the device hosting the implementation, such as latitude and longitude. The API itself is agnostic of the underlying location information sources. Common sources of location information include Global Positioning System (GPS) and location inferred from network signals such as IP address, RFID, WiFi and Bluetooth MAC addresses, and GSM/CDMA cell IDs, as well as user input. No guarantee is given that the API returns the device actual location.
The API is designed to enable both one-shot position requests and repeated position updates, as well as the ability to explicitly query the cached positions. Location information is represented by latitude and longitude coordinates.
See also http://en.wikipedia.org/wiki/W3C_Geolocation_API'!
#( #NavigatorGeolocation #Geolocation
#PositionOptions #GeolocationPosition
#GeolocationCoordinates #PositionError
) do: [:each| GeolocationObject subclass: each ]!
! BrowserNavigator methodsFor: 'Geolocation-converting' !
asNavigatorGeolocation
" Return the receiver adapted to NavigatorGeolocation interface (or nil). "
^NavigatorGeolocation @ self handle! !
! BrowserNavigator methodsFor: 'Geolocation-converting' !
asGeolocation
" Return the receiver adapted to Geolocation interface (or nil). "
| api |
api := self asNavigatorGeolocation.
api isNil ifTrue: [ ^nil ].
^api geolocation! !
NavigatorGeolocation buildTypedGetters: #(
#(#geolocation #Geolocation)
)!
Geolocation buildFunctions: #(
#( #getCurrentPosition:errorCallback:options: #( #successCallback #errorCallback #options ) )
#( #getCurrentPosition:errorCallback: #( #successCallback #errorCallback ) )
#( #getCurrentPosition: #( #successCallback ) )
#( #watchPosition:errorCallback:options: #( #successCallback #errorCallback #options ) )
#( #watchPosition:errorCallback: #( #successCallback #errorCallback ) )
#( #watchPosition: #( #successCallback ) )
#( #clearWatch: #( #watchId ) )
)!
PositionOptions buildBooleanAccessors: #( #enableHighAccuracy )!
PositionOptions buildNumberAccessors: #( #timeout #maximumAge )!
GeolocationPosition buildGetters: #( #timestamp )!
GeolocationPosition buildTypedGetters: #(
#( #coords #GeolocationCoordinates )
)!
GeolocationCoordinates buildNumberGetters: #(
#latitude #longitude #altitude #accuracy
#altitudeAccuracy #heading #speed
)!
PositionError buildGetters: #( #code #message )!
! PositionError class methodsFor: #constants !
permissionDenied
" Return the constant value PERMISSION_DENIED "
^1! !
! PositionError class methodsFor: #constants !
positionUnavailable
" Return the constant value POSITION_UNAVAILABLE "
^2! !
! PositionError class methodsFor: #constants !
timeout
" Return the constant value TIMEOUT "
^3! !