I’m trying to pass the result from navigator.geolocation.watchPosition() to the server with Meteor.call, but all I get is an empty object.
If I pass any other object, it arrives just fine. As a workaround I’m mapping the relevant attributes of the geolocation object to a new object, but I’d rather just pass it in intact.
From the code you show, your onSuccess function is passing you a position, and your passing this.state.position into the function when you should just be passing position?
Thanks @lucfranken - pardon my ignorance, but when is an object not an object? (Coming from Ruby where everything is an object in the truest sense of the word, it seems to have multiple meanings in JS).
The browser shows it as Geoposition {}
How would I go about converting it to an object? Thanks!
Thanks @pmwisdom - that was a transcription error while trying to simplify the example code. I am currently copying some of the object attributes to this.state, but should have changed that for the “raw” object.
There are no errors in the error handler, and I can log the geolocation object to the console.
@shock Hm, okay thanks. Not sure how DDP would view it, but there are no unusual datatypes in the Geoposition object (numbers basically). You can try it in the browser console:
@mbrookes Your going to have to provide more code then that to successfully help you out then. You’ve omitted most of the code that could help us help you. When your onSuccess fires, if you console.log(position) does it read out the correct geolocation object in the console?
The way you’ve written it it looks like your geolocation call is outside of your React class.
@pmwisdom, not sure what’s missing to debug. I’m not a big fan of dumping a ton of code and expecting others to pick through it and find the relevant bits, so that should be all the pertinent code. I also intentionally tried to “de-React” it (being a Meteor specific question), but missed this.state - I’ll edit that.
To your question though (and thanks for helping), yes, console.log(position) in onSuccess valid.
And even coords prop will not be enough cause it has some stuff there which cannot be packed seems.
it.coords.longitude is OK etc etc
Now try it in your usecase and let us know.
Maybe I am also just misleading you It is 1:45am here
And I am kinda exhausted from all these APIs of mine little project - search engine above all livestreams solutions I can think of : youtube, twitch, hitbox, periscope, meerkat . And I am noob in elasticsearch, so indexing like total noob
I know the feeling. I wrote a ruby library to standardise across multiple media APIs Apple Music, Amazon, XBox music (as it was then)… It’s a nightmare.
Looks good, thanks. Does it use native GPS in cordova, or is it a wrapper to the HTML5 API? I think I’m going to need support for background GPS (realtime sports tracker app), but no idea how that works…
Geolocation.latLng()
A simple shorthand for currentLocation() when all you need is the latitude and longitude. Returns an object that has lat and lng keys.
So MDG did see a reason to supply it. Maybe the other packages also support such a thing.
Everything @lucfranken said was correct. For background you must use as background tracker, as he linked. Just be sure to be careful when using that one. It uses an older version of Christocracys background plugin. Which hasn’t been updated (for the general non paying public) in a long, long time.
Edit: Addendum, that plugin may or may not work for you depending on your requirements and how many data points you need while using it. It uses whats called geolocation fences and the iOS significant changes library to start and stop geolocation tracking. For example your phone will get one point every few blocks, and then a stream of point after that, and then rinse and repeat.
Geolocation.latLng() is probably geared at giving you an easy object back to interface with things like google maps where all positions are handled via LatLng objects.
Thanks both - seems I am going to struggle then with background GPS with the available cordova plugins, and the commercial version is way above my budget for a personal project. I’ll just have to tell the user to keep the app open I guess. :-/