使用Google电子表格中的脚本从手机中获取当前职位 [英] Getting my current position from my phone with script in Google spreadsheet

查看:64
本文介绍了使用Google电子表格中的脚本从手机中获取当前职位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过Google Apps脚本从手机的GPS数据中获取当前位置(纬度和经度,最好为十进制)?另外,是否可以打开和关闭GPS或至少检测它是打开还是关闭?

这是我尝试做的事情:我用电动助力车去了一些地方,在每个地方我都在电子表格中输入一些数据,例如日期,距上一个位置的距离,我正在使用的电池等等.我的位置是专栏之一.我目前是手动输入的,但是有些职位很常见(例如工作"和家"),如果脚本在编辑时输入了我的职位,将会很方便.

我已经这样做了,但是目前还很原始.现在唯一要做的就是检查是否是工作日,在这种情况下,如果我的最后一个职位是工作",它将输入工作",如果我的最后一个职位是工作",则输入工作".这可以解决最常见的情况,但是我经常去很多地方,因此我认为,如果可以从手机中获取当前的GPS坐标,则可以使用它们来确定我是否在工作,在家中或我经常光顾的杂货店之一.

我一直在寻找答案,但是我所能找到的就是如何将地址转换为坐标,反之亦然,这显然不是我要找的东西.

解决方案

我认为我们可以尝试 Geolocation API

这样的事情(请注意处理用户同意):

  navigator.geolocation.getCurrentPosition(function(location){console.log(location.coords.latitude);console.log(location.coords.longitude);console.log(location.coords.accuracy);}); 

https://developer.mozilla.org/zh-CN/docs/Web/API/Geolocation_API

信用:从网络浏览器中获取GPS位置

Is there a way to get my current position (latitudes and longitudes, preferably in decimal form) from my phone's GPS data with a Google Apps Script? Also, is it possible to turn GPS on and off or at least detect if it's on or off?

Here's what I try to do: I go to places with my electric moped, and at every place I enter some data in a spreadsheet, such as date, distance since last position, which battery I'm using and more. One of the columns is my position. I currently enter it manually, but some positions are very common (for instance "Work" and "Home") and it would be convenient if a script entered my position for me on edit.

I do that already, but it's very primitive at the moment. The only thing it does now, is check if it's a working day, and in that case, if my last position was "Home", it will enter "Work", and "Home" if my last position was "Work". That takes care of the most common situations, but there are a few more places I go to often, so I figured that if I can get my current GPS coordinates from my phone, I could use them for figuring out if I'm at work, at home, or at one of the grocery stores I visit often or whatever.

I have searched for the answer, but all I can find is how to convert addresses to coordinates and the other way around, which obviously is not what I'm looking for at all.

解决方案

I think we can try Geolocation API

Something like this (be mindful about handling user consent):

navigator.geolocation.getCurrentPosition(function(location) {
  console.log(location.coords.latitude);
  console.log(location.coords.longitude);
  console.log(location.coords.accuracy);
});

https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API

Credits : Get GPS location from the web browser

这篇关于使用Google电子表格中的脚本从手机中获取当前职位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆