Nativescript-geolocation NOT working after Updating Nativescript using a JS Project

plugins

#1

I updated {N} here is my info
$ tns info
All NativeScript components versions information
┌──────────────────┬─────────────────┬────────────────┬───────────────┐
│ Component │ Current version │ Latest version │ Information │
│ nativescript │ 3.2.1 │ 3.2.1 │ Up to date │
│ tns-core-modules │ 3.2.0 │ 3.2.0 │ Up to date │
│ tns-android │ 3.2.0 │ 3.2.0 │ Up to date │
│ tns-ios │ │ 3.2.0 │ Not installed │
└──────────────────┴─────────────────┴────────────────┴───────────────┘
Now after this update i cant get my current location from the same code that run perfectly before updating, is it because it has to be in TS not JS?, can a TS Plugin run on a JS project? @tjvantoll @jen.looper


#2

Hey @devyaz,

A JavaScript app can definitely use TypeScript-written plugins. NativeScript only executes JavaScript code, so NativeScript is only running the plugin’s compiled JavaScript code—even in TypeScript-written apps.

Could you include the code that you’re using and isn’t working? As a side note: the NativeScript Playground (https://play.nativescript.org/) supports the geolocation plugin, so you could try to recreate the problem you’re having there so we can take a look.

Thanks,
TJ


#3

the code is shared here please try it it should display the lattitude and longitude of current location, i just included the geolocation code from my app!

or as this code
`function onNavigatingTo(args) {
var page = args.object;

geolocation.getCurrentLocation().then(function (loc) {
if (loc) {
homeViewModel.latt = loc.latitude;
homeViewModel.lang = loc.longitude;
console.log(“Location locked !”);
/* args.map.setCenter({
lat: loc.latitude,
lng: loc.longitude,
animated: true
});*/

}

}, function (e) {
dialogs.alert(e.message);
});

}
exports.onNavigatingTo = onNavigatingTo;`


#4

I have done so but just in case here’s the code from Playground!

function onNavigatingTo(args) {

var page = args.object;

geolocation.getCurrentLocation().then(function (loc) {

if (loc) {

  homeViewModel.latt = loc.latitude;

  homeViewModel.lang = loc.longitude;

  console.log("Location locked !");

 /* args.map.setCenter({

    lat: loc.latitude,

    lng: loc.longitude,

    animated: true

  });*/

 

}

}, function (e) {

dialogs.alert(e.message);

});

}

exports.onNavigatingTo = onNavigatingTo;


#5

Hey @devyaz,

I couldn’t get your exact code to work, but check out this example of a JavaScript app that successfully uses the geolocation plugin: https://play.nativescript.org/?template=play-js&id=927hOBfPKw0ZVRwArDWO0. You can scan that Playground instance’s QR code to see the app on your device.

Might be a good reference so we can help figure out why your code snippet isn’t working.


#6

Thanks that code works i owe you @tjvantoll :kissing_closed_eyes::grinning::grinning:


#7

but then its just watching location, its the getCurrentlocation that not working, it doesn’t even throw errors


#8

@tjvantoll Today i Updated {N} geolocation and the following code run and work perfectly NOW

  var location = geolocation.getCurrentLocation({desiredAccuracy: 3, updateDistance: 10, maximumAge: 20000, timeout: 20000}).
  then(function(loc) {
  if (loc) {
    console.log("Location locked !");
    latt=loc.latitude; //passed to Mapbox
    lang=loc.longitude;  //passed to Mapbox
  //console.log("Current location is: " + JSON.stringify(loc));
  }
  }, function(e){
  console.log("Error: " + e.message);
  });

#9

i use the same code and i get this error

Cannot read property ‘GoogleApiAvailability’ of undefined


#10
var location = geolocation.getCurrentLocation({desiredAccuracy: 3, updateDistance: 10, maximumAge: 20000, timeout: 20000}).then(function(loc) {
	if (loc) {
		console.log("Location locked !");
		  latt=loc.latitude;
		  lang=loc.longitude; 
		}
		}, function(e){
		console.log("Error: " + e.message);
		});

and i get this error

Cannot read property ‘GoogleApiAvailability’ of undefined

any ideas??


#11

do you get the “location locked I” from console? if so that tells me you have something amiss in your google maps code, nothing to do with {N} or {N}geolocation, can you share the code of your maps!!


#12

i got it to work with the same code using an older version of the plugin. not using my laptop at moment so i cant be specific about the version


#13

Ok cool mark it as solution!