Gathering detailed insights and metrics for cordova-plugin-geolocation
Gathering detailed insights and metrics for cordova-plugin-geolocation
Gathering detailed insights and metrics for cordova-plugin-geolocation
Gathering detailed insights and metrics for cordova-plugin-geolocation
cordova-background-geolocation-plugin
Cordova Background Geolocation Plugin
cordova-plugin-background-geolocation_sayeh
Cordova Background GeoLocation Plugin
cordova-background-geolocation-lt
Cordova / Capacitor Background Geolocation. The most sophisticated, cross-platform location-tracking and geofencing plugin with battery-conscious motion-detection intelligence.
cordova-plugin-mauron85-background-geolocation
Cordova Background Geolocation Plugin
Apache Cordova Geolocation Plugin
npm install cordova-plugin-geolocation
Typescript
Module System
Node Version
NPM Version
94.2
Supply Chain
99.5
Quality
83.4
Maintenance
100
Vulnerability
88
License
JavaScript (60.7%)
Objective-C (30.94%)
Java (8.36%)
Total Downloads
8,568,053
Last Day
535
Last Week
13,846
Last Month
58,370
Last Year
784,229
Apache-2.0 License
635 Stars
356 Commits
668 Forks
58 Watchers
21 Branches
87 Contributors
Updated on May 07, 2025
Latest Version
5.0.0
Package Id
cordova-plugin-geolocation@5.0.0
Unpacked Size
99.29 kB
Size
24.25 kB
File Count
15
NPM Version
9.5.1
Node Version
18.16.0
Published on
Sep 21, 2023
Cumulative downloads
Total Downloads
Last Day
-2.9%
535
Compared to previous day
Last Week
-13.5%
13,846
Compared to previous week
Last Month
-0.5%
58,370
Compared to previous month
Last Year
-17.5%
784,229
Compared to previous year
1
This plugin provides information about the device's location, such as latitude and longitude.
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. There is no guarantee that the API returns the device's actual location.
To get a few ideas, check out the sample at the bottom of this page or go straight to the reference content.
This API is based on the W3C Geolocation API Specification.
WARNING: Collection and use of geolocation data raises important privacy issues. Your app's privacy policy should discuss how the app uses geolocation data, whether it is shared with any other parties, and the level of precision of the data (for example, coarse, fine, ZIP code level, etc.). Geolocation data is generally considered sensitive because it can reveal user's whereabouts and, if stored, the history of their travels. Therefore, in addition to the app's privacy policy, you should strongly consider providing a just-in-time notice before the app accesses geolocation data (if the device operating system doesn't do so already). That notice should provide the same information noted above, as well as obtaining the user's permission (e.g., by presenting choices for OK and No Thanks). For more information, please see the Privacy Guide.
This plugin defines a global navigator.geolocation
object (for platforms
where it is otherwise missing).
Although the object is in the global scope, features provided by this plugin
are not available until after the deviceready
event.
1 2 document.addEventListener("deviceready", onDeviceReady, false); 3 function onDeviceReady() { 4 console.log("navigator.geolocation works well"); 5 } 6
This requires cordova 5.0+ ( current stable 1.0.0 )
cordova plugin add cordova-plugin-geolocation
Older versions of cordova can still install via the deprecated id ( stale 0.3.12 )
cordova plugin add org.apache.cordova.geolocation
It is also possible to install via repo url directly ( unstable )
cordova plugin add https://github.com/apache/cordova-plugin-geolocation.git
Returns the device's current position to the geolocationSuccess
callback with a Position
object as the parameter. If there is an
error, the geolocationError
callback is passed a
PositionError
object.
navigator.geolocation.getCurrentPosition(geolocationSuccess,
[geolocationError],
[geolocationOptions]);
geolocationSuccess: The callback that is passed the current position.
geolocationError: (Optional) The callback that executes if an error occurs.
geolocationOptions: (Optional) The geolocation options.
1 2 // onSuccess Callback 3 // This method accepts a Position object, which contains the 4 // current GPS coordinates 5 // 6 var onSuccess = function(position) { 7 alert('Latitude: ' + position.coords.latitude + '\n' + 8 'Longitude: ' + position.coords.longitude + '\n' + 9 'Altitude: ' + position.coords.altitude + '\n' + 10 'Accuracy: ' + position.coords.accuracy + '\n' + 11 'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '\n' + 12 'Heading: ' + position.coords.heading + '\n' + 13 'Speed: ' + position.coords.speed + '\n' + 14 'Timestamp: ' + position.timestamp + '\n'); 15 }; 16 17 // onError Callback receives a PositionError object 18 // 19 function onError(error) { 20 alert('code: ' + error.code + '\n' + 21 'message: ' + error.message + '\n'); 22 } 23 24 navigator.geolocation.getCurrentPosition(onSuccess, onError); 25
Since iOS 10 it's mandatory to provide an usage description in the info.plist
if trying to access privacy-sensitive data. When the system prompts the user to allow access, this usage description string will displayed as part of the permission dialog box, but if you didn't provide the usage description, the app will crash before showing the dialog. Also, Apple will reject apps that access private data but don't provide an usage description.
This plugins requires the following usage description:
NSLocationWhenInUseUsageDescription
describes the reason that the app accesses the user's location, this is used while the app is running in the foreground.NSLocationAlwaysAndWhenInUseUsageDescription
describes the reason that the app is requesting access to the user’s location information at all times. Use this key if your iOS app accesses location information while running in the background and foreground.NSLocationAlwaysUsageDescription
describes the reason that the app is requesting access to the user's location at all times. Use this key if your app accesses location information in the background and you deploy to a target earlier than iOS 11. For iOS 11 and later, add both NSLocationAlwaysUsageDescription
and NSLocationAlwaysAndWhenInUseUsageDescription
to your app’s Info.plist
file with the same message.To add these entries into the info.plist
, you can use the edit-config
tag in the config.xml
like this:
<edit-config target="NSLocationWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
<edit-config target="NSLocationAlwaysAndWhenInUseUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
<edit-config target="NSLocationAlwaysUsageDescription" file="*-Info.plist" mode="merge">
<string>need location access to find things nearby</string>
</edit-config>
For historic reasons, this plugin requires GPS Hardware on Android devices, so your app will not be able to run on devices without. If you want to use this plugin in your app, but you do not require actual GPS Hardware on the device, install the plugin using the variable GPS_REQUIRED set to false:
cordova plugin add cordova-plugin-geolocation --variable GPS_REQUIRED="false"
If Geolocation service is turned off the onError
callback is invoked after timeout
interval (if specified).
If timeout
parameter is not specified then no callback is called.
Returns the device's current position when a change in position is detected.
When the device retrieves a new location, the geolocationSuccess
callback executes with a Position
object as the parameter. If
there is an error, the geolocationError
callback executes with a
PositionError
object as the parameter.
var watchId = navigator.geolocation.watchPosition(geolocationSuccess,
[geolocationError],
[geolocationOptions]);
geolocationSuccess: The callback that is passed the current position.
geolocationError: (Optional) The callback that executes if an error occurs.
geolocationOptions: (Optional) The geolocation options.
navigator.geolocation.clearWatch
to stop watching for changes in position.1 2 // onSuccess Callback 3 // This method accepts a `Position` object, which contains 4 // the current GPS coordinates 5 // 6 function onSuccess(position) { 7 var element = document.getElementById('geolocation'); 8 element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' + 9 'Longitude: ' + position.coords.longitude + '<br />' + 10 '<hr />' + element.innerHTML; 11 } 12 13 // onError Callback receives a PositionError object 14 // 15 function onError(error) { 16 alert('code: ' + error.code + '\n' + 17 'message: ' + error.message + '\n'); 18 } 19 20 // Options: throw an error if no update is received every 30 seconds. 21 // 22 var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { timeout: 30000 }); 23
Optional parameters to customize the retrieval of the geolocation
Position
.
{ maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };
enableHighAccuracy: Provides a hint that the application needs the best possible results. By default, the device attempts to retrieve a Position
using network-based methods. Setting this property to true
tells the framework to use more accurate methods, such as satellite positioning. (Boolean)
timeout: The maximum length of time (milliseconds) that is allowed to pass from the call to navigator.geolocation.getCurrentPosition
or geolocation.watchPosition
until the corresponding geolocationSuccess
callback executes. If the geolocationSuccess
callback is not invoked within this time, the geolocationError
callback is passed a PositionError.TIMEOUT
error code. (Note that when used in conjunction with geolocation.watchPosition
, the geolocationError
callback could be called on an interval every timeout
milliseconds!) (Number)
maximumAge: Accept a cached position whose age is no greater than the specified time in milliseconds. (Number)
If Geolocation service is turned off the onError
callback is invoked after timeout
interval (if specified).
If timeout
parameter is not specified then no callback is called.
Stop watching for changes to the device's location referenced by the
watchID
parameter.
navigator.geolocation.clearWatch(watchID);
watchPosition
interval to clear. (String)1 2 // Options: watch for changes in position, and use the most 3 // accurate position acquisition method available. 4 // 5 var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { enableHighAccuracy: true }); 6 7 // ...later on... 8 9 navigator.geolocation.clearWatch(watchID); 10
Contains Position
coordinates and timestamp, created by the geolocation API.
coords: A set of geographic coordinates. (Coordinates)
timestamp: Creation timestamp for coords
. (DOMTimeStamp)
A Coordinates
object is attached to a Position
object that is
available to callback functions in requests for the current position.
It contains a set of properties that describe the geographic coordinates of a position.
latitude: Latitude in decimal degrees. (Number)
longitude: Longitude in decimal degrees. (Number)
altitude: Height of the position in meters above the ellipsoid. (Number)
accuracy: Accuracy level of the latitude and longitude coordinates in meters. (Number)
altitudeAccuracy: Accuracy level of the altitude coordinate in meters. (Number)
heading: Direction of travel, specified in degrees counting clockwise relative to the true north. (Number)
speed: Current ground speed of the device, specified in meters per second. (Number)
altitudeAccuracy: Not supported by Android devices, returning null
.
The PositionError
object is passed to the geolocationError
callback function when an error occurs with navigator.geolocation.
code: One of the predefined error codes listed below.
message: Error message describing the details of the error encountered.
PositionError.PERMISSION_DENIED
PositionError.POSITION_UNAVAILABLE
PositionError.TIMEOUT
timeout
included in geolocationOptions
. When used with navigator.geolocation.watchPosition
, this error could be repeatedly passed to the geolocationError
callback every timeout
milliseconds.Use this plugin to help users find things near them such as Groupon deals, houses for sale, movies playing, sports and entertainment events and more.
Here's a "cookbook" of ideas to get you started. In the snippets below, we'll show you some basic ways to add these features to your app.
1 2function getWeatherLocation() { 3 4 navigator.geolocation.getCurrentPosition 5 (onWeatherSuccess, onWeatherError, { enableHighAccuracy: true }); 6} 7
1 2// Success callback for get geo coordinates 3 4var onWeatherSuccess = function (position) { 5 6 Latitude = position.coords.latitude; 7 Longitude = position.coords.longitude; 8 9 getWeather(Latitude, Longitude); 10} 11 12// Get weather by using coordinates 13 14function getWeather(latitude, longitude) { 15 16 // Get a free key at http://openweathermap.org/. Replace the "Your_Key_Here" string with that key. 17 var OpenWeatherAppKey = "Your_Key_Here"; 18 19 var queryString = 20 'http://api.openweathermap.org/data/2.5/weather?lat=' 21 + latitude + '&lon=' + longitude + '&appid=' + OpenWeatherAppKey + '&units=imperial'; 22 23 $.getJSON(queryString, function (results) { 24 25 if (results.weather.length) { 26 27 $.getJSON(queryString, function (results) { 28 29 if (results.weather.length) { 30 31 $('#description').text(results.name); 32 $('#temp').text(results.main.temp); 33 $('#wind').text(results.wind.speed); 34 $('#humidity').text(results.main.humidity); 35 $('#visibility').text(results.weather[0].main); 36 37 var sunriseDate = new Date(results.sys.sunrise); 38 $('#sunrise').text(sunriseDate.toLocaleTimeString()); 39 40 var sunsetDate = new Date(results.sys.sunrise); 41 $('#sunset').text(sunsetDate.toLocaleTimeString()); 42 } 43 44 }); 45 } 46 }).fail(function () { 47 console.log("error getting location"); 48 }); 49} 50 51// Error callback 52 53function onWeatherError(error) { 54 console.log('code: ' + error.code + '\n' + 55 'message: ' + error.message + '\n'); 56} 57
1 2// Watch your changing position 3 4function watchWeatherPosition() { 5 6 return navigator.geolocation.watchPosition 7 (onWeatherWatchSuccess, onWeatherError, { enableHighAccuracy: true }); 8} 9 10// Success callback for watching your changing position 11 12var onWeatherWatchSuccess = function (position) { 13 14 var updatedLatitude = position.coords.latitude; 15 var updatedLongitude = position.coords.longitude; 16 17 if (updatedLatitude != Latitude && updatedLongitude != Longitude) { 18 19 Latitude = updatedLatitude; 20 Longitude = updatedLongitude; 21 22 // Calls function we defined earlier. 23 getWeather(updatedLatitude, updatedLongitude); 24 } 25} 26
Both Bing and Google have map services. We'll use Google's. You'll need a key but it's free if you're just trying things out.
Add a reference to the maps service.
1 2 <script src="https://maps.googleapis.com/maps/api/js?key=Your_API_Key"></script> 3
Then, add code to use it.
1 2var Latitude = undefined; 3var Longitude = undefined; 4 5// Get geo coordinates 6 7function getMapLocation() { 8 9 navigator.geolocation.getCurrentPosition 10 (onMapSuccess, onMapError, { enableHighAccuracy: true }); 11} 12 13// Success callback for get geo coordinates 14 15var onMapSuccess = function (position) { 16 17 Latitude = position.coords.latitude; 18 Longitude = position.coords.longitude; 19 20 getMap(Latitude, Longitude); 21 22} 23 24// Get map by using coordinates 25 26function getMap(latitude, longitude) { 27 28 var mapOptions = { 29 center: new google.maps.LatLng(0, 0), 30 zoom: 1, 31 mapTypeId: google.maps.MapTypeId.ROADMAP 32 }; 33 34 map = new google.maps.Map 35 (document.getElementById("map"), mapOptions); 36 37 38 var latLong = new google.maps.LatLng(latitude, longitude); 39 40 var marker = new google.maps.Marker({ 41 position: latLong 42 }); 43 44 marker.setMap(map); 45 map.setZoom(15); 46 map.setCenter(marker.getPosition()); 47} 48 49// Success callback for watching your changing position 50 51var onMapWatchSuccess = function (position) { 52 53 var updatedLatitude = position.coords.latitude; 54 var updatedLongitude = position.coords.longitude; 55 56 if (updatedLatitude != Latitude && updatedLongitude != Longitude) { 57 58 Latitude = updatedLatitude; 59 Longitude = updatedLongitude; 60 61 getMap(updatedLatitude, updatedLongitude); 62 } 63} 64 65// Error callback 66 67function onMapError(error) { 68 console.log('code: ' + error.code + '\n' + 69 'message: ' + error.message + '\n'); 70} 71 72// Watch your changing position 73 74function watchMapPosition() { 75 76 return navigator.geolocation.watchPosition 77 (onMapWatchSuccess, onMapError, { enableHighAccuracy: true }); 78} 79
You can use the same Google key for this.
Add a reference to the places service.
1 2<script src= 3"https://maps.googleapis.com/maps/api/js?key=Your_API_Key&libraries=places"> 4</script> 5
Then, add code to use it.
1 2var Map; 3var Infowindow; 4var Latitude = undefined; 5var Longitude = undefined; 6 7// Get geo coordinates 8 9function getPlacesLocation() { 10 navigator.geolocation.getCurrentPosition 11 (onPlacesSuccess, onPlacesError, { enableHighAccuracy: true }); 12} 13 14// Success callback for get geo coordinates 15 16var onPlacesSuccess = function (position) { 17 18 Latitude = position.coords.latitude; 19 Longitude = position.coords.longitude; 20 21 getPlaces(Latitude, Longitude); 22 23} 24 25// Get places by using coordinates 26 27function getPlaces(latitude, longitude) { 28 29 var latLong = new google.maps.LatLng(latitude, longitude); 30 31 var mapOptions = { 32 33 center: new google.maps.LatLng(latitude, longitude), 34 zoom: 15, 35 mapTypeId: google.maps.MapTypeId.ROADMAP 36 37 }; 38 39 Map = new google.maps.Map(document.getElementById("places"), mapOptions); 40 41 Infowindow = new google.maps.InfoWindow(); 42 43 var service = new google.maps.places.PlacesService(Map); 44 service.nearbySearch({ 45 46 location: latLong, 47 radius: 500, 48 type: ['store'] 49 }, foundStoresCallback); 50 51} 52 53// Success callback for watching your changing position 54 55var onPlacesWatchSuccess = function (position) { 56 57 var updatedLatitude = position.coords.latitude; 58 var updatedLongitude = position.coords.longitude; 59 60 if (updatedLatitude != Latitude && updatedLongitude != Longitude) { 61 62 Latitude = updatedLatitude; 63 Longitude = updatedLongitude; 64 65 getPlaces(updatedLatitude, updatedLongitude); 66 } 67} 68 69// Success callback for locating stores in the area 70 71function foundStoresCallback(results, status) { 72 73 if (status === google.maps.places.PlacesServiceStatus.OK) { 74 75 for (var i = 0; i < results.length; i++) { 76 77 createMarker(results[i]); 78 79 } 80 } 81} 82 83// Place a pin for each store on the map 84 85function createMarker(place) { 86 87 var placeLoc = place.geometry.location; 88 89 var marker = new google.maps.Marker({ 90 map: Map, 91 position: place.geometry.location 92 }); 93 94 google.maps.event.addListener(marker, 'click', function () { 95 96 Infowindow.setContent(place.name); 97 Infowindow.open(Map, this); 98 99 }); 100} 101 102// Error callback 103 104function onPlacesError(error) { 105 console.log('code: ' + error.code + '\n' + 106 'message: ' + error.message + '\n'); 107} 108 109// Watch your changing position 110 111function watchPlacesPosition() { 112 113 return navigator.geolocation.watchPosition 114 (onPlacesWatchSuccess, onPlacesError, { enableHighAccuracy: true }); 115} 116
Digital photos can contain geo coordinates that identify where the picture was taken.
Use Flickr API's to find pictures that folks have taken near you. Like Google services, you'll need a key, but it's free if you just want to try things out.
1 2var Latitude = undefined; 3var Longitude = undefined; 4 5// Get geo coordinates 6 7function getPicturesLocation() { 8 9 navigator.geolocation.getCurrentPosition 10 (onPicturesSuccess, onPicturesError, { enableHighAccuracy: true }); 11 12} 13 14// Success callback for get geo coordinates 15 16var onPicturesSuccess = function (position) { 17 18 Latitude = position.coords.latitude; 19 Longitude = position.coords.longitude; 20 21 getPictures(Latitude, Longitude); 22} 23 24// Get pictures by using coordinates 25 26function getPictures(latitude, longitude) { 27 28 $('#pictures').empty(); 29 30 var queryString = 31 "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=Your_API_Key&lat=" 32 + latitude + "&lon=" + longitude + "&format=json&jsoncallback=?"; 33 34 $.getJSON(queryString, function (results) { 35 $.each(results.photos.photo, function (index, item) { 36 37 var photoURL = "http://farm" + item.farm + ".static.flickr.com/" + 38 item.server + "/" + item.id + "_" + item.secret + "_m.jpg"; 39 40 $('#pictures').append($("<img />").attr("src", photoURL)); 41 42 }); 43 } 44 ); 45} 46 47// Success callback for watching your changing position 48 49var onPicturesWatchSuccess = function (position) { 50 51 var updatedLatitude = position.coords.latitude; 52 var updatedLongitude = position.coords.longitude; 53 54 if (updatedLatitude != Latitude && updatedLongitude != Longitude) { 55 56 Latitude = updatedLatitude; 57 Longitude = updatedLongitude; 58 59 getPictures(updatedLatitude, updatedLongitude); 60 } 61} 62 63// Error callback 64 65function onPicturesError(error) { 66 67 console.log('code: ' + error.code + '\n' + 68 'message: ' + error.message + '\n'); 69} 70 71// Watch your changing position 72 73function watchPicturePosition() { 74 75 return navigator.geolocation.watchPosition 76 (onPicturesWatchSuccess, onPicturesError, { enableHighAccuracy: true }); 77} 78
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
security policy file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
Found 23/28 approved changesets -- score normalized to 8
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
Reason
2 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-05-19
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More