JavaScript API 'Staging'
Using this page for now as a page that will have the latest up-to-date JavaScript API information. Eventually we want to move this page and the info contained within it to docs.phonegap.com.
Geolocation
Related PhoneGap Tutorials
JavaScript Geolocation Interface
Geolocation class
readonly attribute Position lastPosition
- Set to the last-retrieved GPS position after every successful location retrieval.
void getCurrentPosition(successCallback, [errorCallback], [options])
- Retrieves the current GPS position from the device.
- successCallback parameter: handle to a function taking one parameter that handles what to do with the retrieved position. Parameter for this function will be an instance of the Position class.
- errorCallback parameter (optional): handle to a function that handles error in retrieving position.
- options parameter (optional): JavaScript object literal defining members specifying options to the call. For getCurrentPosition, none that apply (yet).
int watchPosition(successCallback, [errorCallback], [options])
- Retrieves the current GPS position from the device at a specified interval.
- Returns an ID to use with clearWatch function below when you want to clear the position watch.
- successCallback parameter: handle to a function taking one parameter that handles what to do with the retrieved position. Parameter for this function will be an instance of the Position class.
- errorCallback parameter (optional): handle to a function that handles error in retrieving position.
- options parameter (optional): JavaScript object literal defining members specifying options to the call. For watchPosition, a 'frequency' member specifies how frequently to check for position (specified in milliseconds).
void clearWatch(int watchId)
- Clears out the watchPosition interval timeout, given the watchId to clear.
- Use the ID returned by watchPosition function above as parameter to pass into this function.
Position class
readonly attribute Coordinates coords
readonly attribute Date timestamp
Coordinates class
readonly attribute double latitude
readonly attribute double longitude
readonly attribute double altitude
readonly attribute double accuracy
readonly attribute double heading
readonly attribute double speed
Accelerometer
Accelerometer class
readonly attribute Position lastPosition
void getCurrentAcceleration(successCallback, [errorCallback], [options])
int watchAcceleration(successCallback, [errorCallback], [options])
void clearWatch(int watchId)
Camera
Camera class
void getPicture(successCallback, [errorCallback], [options])
Notification
Notification class
void beep()
void vibrate()
void blink()
void watchPosition(filter, [successCallback], [errorCallback])
void clearWatch(filter, [successCallback], [errorCallback])
void onReceive(successCallback, errorCallback)
Contacts
Contacts class
void getAllContacts(successCallback, [errorCallback], [options])
Contact class
readonly attribute String name
readonly attribute String[] phone
readonly attribute String address
File IO
File class
void read(fileName, [successCallback], [errorCallback])
void write(fileName, data, mode, [successCallback], [errorCallback])
void createDirectory(directory, [successCallback], [errorCallback])
void deleteDirectory(directory, [successCallback], [errorCallback])
boolean testDirectoryExists(directory, [successCallback], [errorCallback])
void deleteFile(file, [successCallback], [errorCallback])
boolean testFileExists(file, [successCallback], [errorCallback])
long getFreeDiskSpace([successCallback], [errorCallback])
SMS
SMS class
void send(number, message, [successCallback], [errorCallback])
Phone
Phone class
void call(number, [successCallback], [errorCallback])
Maps
Map class
void open(positions, [successCallback], [errorCallback])
Audio
Audio class
void startRecording(file, encoding, successCallback, [errorCallback])
void stopRecording(successCallback, [errorCallback])
void startPlaying(filename, channel, successCallback, [errorCallback])
void stopPlaying(channel, successCallback, [errorCallback])
long getDuration(filename, successCallback, [errorCallback])
long getCurrentPosition(filename, successCallback, [errorCallback])
void setOutputDevice(device, successCallback, [errorCallback])
string getOutputDevice(successCallback, [errorCallback])
Settings
Settings class
string getNetworkOperatorName([successCallback], [errorCallback])
string getVoicemailNumber([successCallback], [errorCallback])
string getTimeZoneID([successCallback], [errorCallback])
string getSimCountryIso([successCallback], [errorCallback])
string getLine1Number([successCallback], [errorCallback])
HTTP
HTTP class
void get(url, file, channel, successCallback, [errorCallback])
Comments (17)
mboehmer said
at 4:57 pm on Jan 3, 2009
How close is this API to the draft of the W3C Location API?
Dave Johnson said
at 11:25 am on Jan 4, 2009
The geo stuff is going to be exactly like that of the W3C geo API. Everything else is loosely modeled on that same pattern.
Pete Strickler said
at 11:56 am on Jan 19, 2009
Am I correct in believing that the File IO section has not been implemented yet? (Specifically on iPhone)
Is this something that is being worked on? Or is it just a dream at the moment?
Pete Strickler said
at 3:13 pm on Jan 19, 2009
Never mind, I did figure out how to store and load local file data using SQLite in Javascript. I'll try to write a short tutorial on that shortly... :-)
smilbandit said
at 7:06 am on Apr 3, 2009
Anyone know an example using the get function of the http class?
pb said
at 6:32 am on Apr 20, 2009
Let's assume, MobileSafari would get W3C compatible with OS 3.0 for sound and geolocation - would code developed for PhoneGap be compatible with that MobileSafari implementation?
hari said
at 1:24 pm on Apr 30, 2009
Is it possible to retrieve "deviceID" i.e aUNIQUE identification number for the this particular device ( iPhone) and or Android. Thanks
hari said
at 1:28 pm on Apr 30, 2009
ALSO ... you guys are the best.. I spent several hours learning(well..trying to learn) Objective-C. This saves me a lot of time.
Zach said
at 7:30 pm on May 7, 2009
As far as I can tell, the HTTP class doesn't have a JS interface implemented yet.
Joel said
at 8:56 pm on Sep 3, 2009
Pardon my ignorance, but if the class is "Accelerometer" (capital 'A') and the method is "watchAccelerometer" why is the call in the sample code read "timer = navigator.accelerometer.watchAcceleration(suc,fail,opt);"??
Is this documentation out of date?
Dave Johnson said
at 2:00 pm on Sep 7, 2009
@Joel yes it is watchAcceleration - updated it on the wiki now!
Soon said
at 11:19 pm on Apr 1, 2010
I am new to both Android and PhoneGap. I wish to test write an application that write files and read files (under a directory within Android file system)
I have setup eclipse + android simulate. Is there any Example for method below?
void read(fileName, [successCallback], [errorCallback])
void write(fileName, data, mode, [successCallback], [errorCallback])
void createDirectory(directory, [successCallback], [errorCallback])
void deleteDirectory(directory, [successCallback], [errorCallback])
boolean testDirectoryExists(directory, [successCallback], [errorCallback])
void deleteFile(file, [successCallback], [errorCallback])
boolean testFileExists(file, [successCallback], [errorCallback])
long getFreeDiskSpace([successCallback], [errorCallback])
Karim said
at 3:37 pm on Jun 26, 2010
Hello, I am new to phonegap however I am writting an app and will like to give the users the option to generate an email populating many of the calculations done by the app on the email content. Is there an email API to achieve this?
suryapavan said
at 12:22 am on Jul 23, 2010
Hello.. I want to access the files(images) from Blackberry's Image gallery.. How can I do this?
suryapavan said
at 2:06 am on Jul 24, 2010
Is it possible?
JITENDRA said
at 4:48 am on Jul 26, 2010
How can I access Calendar and Contacts API in Phonegap ?
I think for Contacts the JavaScript API that can be used is getAllContacts(success Callback,[errorCallback],[options]);
is there any example showing its use ?
What about Calendar API ?
Waiting for a favorable reply soon.
JITENDRA said
at 3:47 am on Jul 27, 2010
Help needed !
I want to know how to Export/Read Calendar event and write that into a "text" file or how to read "text" file having a Calendar event's data and fill the respective fields in calendar using PHONEGAP ?
Any code will be a great help !
Thanks in advance.
Jitendra
You don't have permission to comment on this page.