This sample shows you how to use the Geolocation API to get geolocation information about a device from the device GPS, network IP address, RFID, WiFi and Bluetooth MAC address and GSM/CDMA cell IDs.
Supported mobile platforms: iOS, Android, Windows Phone
Developed with: Apache Cordova 3.7.0
This sample shows how to use the following methods of the Geolocation API.
- getCurrentPosition(): Returns the position of the device to the success handler as a
Position
object. If the retrieval of geolocation information is unsuccessful, the error handler is called with ageolocationError
object as argument. This method takes as third argumentgeolocationOptions
objects. - watchPosition(): Watches the change of latitude and longitude of the device. When the position of the device changes, this method calls its success handler with a
Position
object as argument and returns awatchID
object. If the retrieval of geolocation information is unsuccessful or the device position has not changed during the specified timeout, the error handler is called with ageolocationError
object as argument. This method takes as third argumentgeolocationOptions
objects. To set the timeout, usegeolocationOptions
. - clearWatch(): Stops watching for changes in the device latitude and longitude. This method clears the
geolocation.watchPosition
that is referenced bywatchID
.
Platform | Home | Geolocation Data |
---|---|---|
All | ![]() |
![]() |
Apart from exploring the sample code base in GitHub, you can also clone and run the sample in your preferred AppBuilder client.
With the AppBuilder in-browser client, you can develop hybrid and NativeScript cross-platform mobile apps from your browser. You can use the in-browser client at https://platform.telerik.com.
- Click Try in AppBuilder above.
- Provide your login credentials, if prompted.
With the AppBuilder Windows client, you can develop hybrid and NativeScript cross-platform mobile apps from your Windows desktop. You can download and install the Windows client from http://www.telerik.com/appbuilder/windows-client.
- Verify that the AppBuilder Windows client is running and you are logged in the Telerik Platform in the account in which you want to develop your application.
- In the dashboard, click Samples and select Hybrid.
- From the Workspace drop-down menu, select the workspace in which you want to develop your application.
- Select Core APIs.
- Select Geolocation.
- (Optional) Rename the project.
- Click Clone.
With the AppBuilder Windows client, you can quickly test your apps on device, in the simulator or in the native emulators.
- Run in the device simulator.
- Run in the companion app.
- Run in the native emulators.
- Deploy on device via QR code.
- Deploy via cable connection.
With the AppBuilder extension for Visual Studio, you can develop hybrid and NativeScript cross-platform mobile apps from Microsoft Visual Studio. You can download and install the extension from http://www.telerik.com/appbuilder/visual-studio-extension.
- Verify that the AppBuilder extension for Visual Studio is running and you are logged in the Telerik Platform in the account in which you want to develop your application.
- Select AppBuilder → Get Sample.
- Select Hybrid.
- Select Core APIs.
- Select Geolocation.
- (Optional) Rename the project.
- Click Get.
The extension for Visual Studio copies the sample files locally. The extension creates a new solution and project and loads them.
With the AppBuilder extension for Visual Studio, you can quickly test your apps on device, in the simulator or in the native emulators.
- Run in the device simulator.
- Run in the companion app.
- Run in the native emulators.
- Deploy on device via QR code.
- Deploy via cable connection.
With the AppBuilder command-line interface, you can develop hybrid and NativeScript cross-platform mobile apps from the command line. You can learn how to add the AppBuilder commands to your command line from http://www.telerik.com/appbuilder/command-line-interface.
-
Verify that a command prompt is running and you are logged in the Telerik Platform in the account in which you want to develop your application.
-
To list the available samples, run the following command.
appbuilder sample
-
Run the clone command for the sample as listed by
appbuilder sample
.appbuilder sample clone geolocation
The AppBuilder command-line interface shows the following message: Successfully initialized project in the folder!
With the AppBuilder command-line interface, you can quickly test your apps on device, in the simulator or in the native emulators.