rranjan
September 30, 2016, 9:44am
1
How can i get Latitude and Longitude from IONIC Cordova.
I am using following plugin for getting Lat/Lng.
cordova-plugin-geolocation 2.1.0 “Geolocation”
And
var options = { timeout: 3000, enableHighAccuracy: true };
document.addEventListener('deviceready', function () {
navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
});
function onSuccess(position) {
latvalue = position.coords.latitude;
lngvalue = position.coords.longitude;
timestamp = position.timestamp;
alert(latvalue);
}
function onError(error)
{
alert(error);
}
mvrc
September 30, 2016, 10:28am
2
You already have it in latvalue and lngvalue,
but you can also use Geolocation from ionic-native .
import { Geolocation } from 'ionic-native';
Geolocation.getCurrentPosition().then((resp) => {
// resp.coords.latitude
// resp.coords.longitude
})
mvrc:
ionic-nativ
Hi mvrc,
will you provide any script for this. It will help to me.
Thanks.
I am using following code, but some time i got Lat/Lng on some android device and sometime not.
var options = { timeout: 3000, enableHighAccuracy: true };
document.addEventListener(‘deviceready’, function () {
navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
});
function onSuccess(position) {
latvalue = position.coords.latitude;
lngvalue = position.coords.longitude;
timestamp = position.timestamp;
alert(latvalue);
}
function onError(error)
{
alert(error);
}
mvrc
October 3, 2016, 10:54am
5
Oh yes, i have the same problem.
You just have to store latvalue and lngvalue and only read this variables.
So when you have an error, latvalue and lngvalue remains the same.
However, some phones have gps with bad precision, you should try with this options :
var options = { timeout: 3000, enableHighAccuracy: false };