All Projects → AhmedMSayed → ti.locationservices

AhmedMSayed / ti.locationservices

Licence: other
Titanium Location Services Module for Android

Programming Languages

java
68154 projects - #9 most used programming language
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to ti.locationservices

titanium-alternate-icons
Leverage the ability to change the app icon in iOS 10.3+
Stars: ✭ 24 (+84.62%)
Mutual labels:  titanium, titanium-module
ti.playservices
Titanium module for Google Play Services
Stars: ✭ 19 (+46.15%)
Mutual labels:  titanium, titanium-module
TiDropboxAPIv2
Titanium Appcelerator Javascript Dropbox API v2
Stars: ✭ 13 (+0%)
Mutual labels:  titanium-module, titanium-modules
ti.youtube
A small library to get the URL of the desired YouTube video ID to use it natively in Ti.Media.VideoPlayer.
Stars: ✭ 13 (+0%)
Mutual labels:  titanium, titanium-module
ti.paint
Touch-based painting with the Titanium SDK.
Stars: ✭ 27 (+107.69%)
Mutual labels:  titanium, titanium-module
av.imageview
Titanium native ImageView module that extends the default Titanium ImageView with more capabilities and a different caching system.
Stars: ✭ 97 (+646.15%)
Mutual labels:  titanium, titanium-module
ti.moddevguide
Appcelerator Titanium native Module Guide
Stars: ✭ 39 (+200%)
Mutual labels:  titanium, titanium-module
ti.admob
Use the Google AdMob SDK on iOS and Android with Titanium
Stars: ✭ 51 (+292.31%)
Mutual labels:  titanium, titanium-module
titanium-apple-sign-in
Use the iOS 13+ Apple Sign In API with Titanium
Stars: ✭ 29 (+123.08%)
Mutual labels:  titanium, titanium-module
abifestival-app
Cross-platform festival-app built with the Appcelerator Titanium framework
Stars: ✭ 16 (+23.08%)
Mutual labels:  titanium
To.BounceView
A bouncing view widget for Titanium
Stars: ✭ 49 (+276.92%)
Mutual labels:  titanium
titanium-es6-sample
An ES6+ sample app for Appcelerator Titanium.
Stars: ✭ 11 (-15.38%)
Mutual labels:  titanium
ti.detect
A simple Titanium library which detects things for you
Stars: ✭ 15 (+15.38%)
Mutual labels:  titanium-module
titanium-socketio
Use the native Socket.io SDK's with Axway Titanium.
Stars: ✭ 25 (+92.31%)
Mutual labels:  titanium
ti.coremotion
Support for the native iOS CoreMotion framework in Appcelerator Titanium
Stars: ✭ 15 (+15.38%)
Mutual labels:  titanium
titanium-calendar
An easy to use iOS modal calendar for selecting dates. Based on the awesome PDTSimpleCalendar library.
Stars: ✭ 15 (+15.38%)
Mutual labels:  titanium
titanium-vue
Use Vue.js to easily create native mobile apps with Axway Appcelerator Titanium.
Stars: ✭ 45 (+246.15%)
Mutual labels:  titanium
titanium-firebase-analytics
Use the Firebase Analytics SDK in Axway Titanium 🚀
Stars: ✭ 33 (+153.85%)
Mutual labels:  titanium
titanium-material
Use the native Material UI/UX framework (https://github.com/CosmicMind/Material) in Titanium!
Stars: ✭ 14 (+7.69%)
Mutual labels:  titanium
nl.fokkezb.button
Bootstrap Button widget for Appcelerator (Titanium)
Stars: ✭ 72 (+453.85%)
Mutual labels:  titanium

Titanium Location Services Module for Android

Turn on GPS settings automatically and get your current or last location.

Install

  1. Get the module v2.0 from the releases page.
  2. Unzip it, put it in your Titanium project modules folder.
  3. Require the module in your application by adding it in your tiapp.xml.
<modules>
  <module version="2.0.0">ti.locationservices</module>
</modules>

Example

const win = Ti.UI.createWindow({
	backgroundColor: 'white'
});

const view = Ti.UI.createView({
	layout: 'vertical',
	height: Ti.UI.SIZE,
	width: Ti.UI.FILL
});

const myLocation = Ti.UI.createLabel({
	text: "My Location",
	color: "#000",
	font: {
		fontSize: '16sp'
	}
});

const getMyCurrentLocation = Ti.UI.createButton({
	title: "Get Current Location",
	color: "#fff",
	backgroundColor: "teal",
	font: {
		fontSize: '16sp'
	},
	top: 24
});

const getMyLastLocation = Ti.UI.createButton({
	title: "Get Last Location",
	color: "#fff",
	backgroundColor: "teal",
	font: {
		fontSize: '16sp'
	},
	top: 16
});

view.add(myLocation);
view.add(getMyCurrentLocation);
view.add(getMyLastLocation);
win.add(view);

//Import Location Services Module
const locationservices = require('ti.locationservices');

getMyCurrentLocation.addEventListener("click", () => {
	locationservices.checkLocationSettings({
		onComplete: (check) => {
			if (check.success) {
				locationservices.getCurrentLocation({
					onComplete: (location) => {
						if (location.success) {
							myLocation.text = `Lat : ${location.coords.latitude}\nLong : ${location.coords.longitude}`;
						} else {
							console.error(location.message);
						}
					}
				});
			} else {
				console.error(check.message);
			}
		}
	});
});

getMyLastLocation.addEventListener("click", () => {
	locationservices.getLastLocation({
		onComplete: (location) => {
			if (location.success) {
				myLocation.text = `Lat : ${location.coords.latitude}\nLong : ${location.coords.longitude}`;
			} else {
				console.error(location.message);
			}
		}
	});
});

win.addEventListener('open', () => {
	if (!Ti.Geolocation.hasLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE)) {
		Ti.Geolocation.requestLocationPermissions(Ti.Geolocation.AUTHORIZATION_WHEN_IN_USE, (e) => {
			if (!e.success) {
				console.warn("Permissions is denied");
			}
		});
	}
});

win.open();

Methods

checkLocationSettings()

This method makes it easy for an app to ensure that the device's system settings are properly configured for the app's location needs. It will invoke a dialog that allows the user to enable the necessary location settings with a single tap.

locationservices.checkLocationSettings({
	onComplete: (check) => {
		if (!check.success) {
			console.error(check.message);
		}
	}
});

getCurrentLocation()

Returns a single current location fix on the device.

locationservices.getCurrentLocation({
	onComplete: (location) => {
		if (location.success) {
			console.info(location)
		} else {
			console.error(location.message);
		}
	}
});

getLastLocation()

Returns a single recent cached location currently available on the device.

If a location is not available, which should happen very rarely, null will be returned

locationservices.getLastLocation({
	onComplete: (location) => {
		if (location.success) {
			console.info(location);
		} else {
			console.error(location.message);
		}
	}
});

startLocationUpdates({ interval, fastestInterval, priority })

Requests location updates.

This method will keep the Google Play services connection active, so make sure to call stopLocationUpdates when you no longer need it.

  • At first, you want to register a location event listener to get the location updates.
locationservices.addEventListener('location', (location) => {
	console.info(location);
});
  • Then you can start Location Updates
locationservices.startLocationUpdates({
	interval: 10000,
	fastestInterval: 5000,
	priority: locationservices.PRIORITY_HIGH_ACCURACY,
	onComplete: (e) => {
		if (e.success) {
			console.info("startLocationUpdates ::", "DONE");
		} else {
			console.info("startLocationUpdates ::", e.message);
		}
	}
});
  • interval : Set the desired interval for active location updates, in milliseconds.

  • fastestInterval : Explicitly set the fastest interval for location updates, in milliseconds.

  • priority : Set the priority of the request.

stopLocationUpdates()

Removes location updates if you no longer need updates.

locationservices.stopLocationUpdates({
	onComplete: (e) => {
		if (e.success) {
			console.info("stopLocationUpdates ::", "DONE");
		} else {
			console.info("stopLocationUpdates ::", e.message);
		}
	}
});

Constant Summary

Constant Usage
PRIORITY_BALANCED_POWER_ACCURACY Used with startLocationUpdates to request "block" level accuracy.
PRIORITY_HIGH_ACCURACY Used with startLocationUpdates to request the most accurate locations available.
PRIORITY_LOW_POWER Used with startLocationUpdates to request "city" level accuracy.
PRIORITY_NO_POWER Used with startLocationUpdates to request the best accuracy possible with zero additional power consumption.

License

MIT

Author

Ahmed Eissa

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].