不好了!我被困在一个大森林里(好吧,不是真的,只是假设一下),我不知道我在哪里!
幸好我带了笔记本电脑。但是,当我搜索“地图”时,它说“没有结果”,我是最后一招。
请制作一个以任何两个数字格式输出我的位置的经度和纬度的程序。any two number format包括:
- 一个元组。
- 包含经度和纬度的字符串。
- JSON对象。
- 等等..
可以使用任何API或库。也就是说,您可以查询Google Maps等。(我想,他们并没有废弃他们的API:\)
不好了!我被困在一个大森林里(好吧,不是真的,只是假设一下),我不知道我在哪里!
幸好我带了笔记本电脑。但是,当我搜索“地图”时,它说“没有结果”,我是最后一招。
请制作一个以任何两个数字格式输出我的位置的经度和纬度的程序。any two number format包括:
可以使用任何API或库。也就是说,您可以查询Google Maps等。(我想,他们并没有废弃他们的API:\)
Answers:
navigator.geolocation.watchPosition(x=>alert([(y=x.coords).latitude,y.longitude]))
在线尝试!(由于某种原因,这在代码段中不起作用)。
navigator对象是BOM的一部分。geolocation是其属性,也是一个对象,其中包含用户的地理位置数据。watchPosition()是一种geolocation对象方法。它接受一个回调函数,该函数在检索地理位置数据后执行。回调函数x=>alert((y=x.coords).latitude+","+y.longitude)是一个匿名(lambda)函数,它接收一个对象x,并用逗号分隔alert()的latitude和longitude属性x.coords。请注意,对象x是在调用回调函数watchPosition()时(即,在检索地理位置数据之后)传递给回调函数的。
watchPosition而不是getCurrentPosition节省5个字节。alert([(y=x.coords).latitude,y.longitude])保存2个以上
for(f in r=navigator.geolocation)r=r[f](x=>alert((y=x.coords).latitude+","+y.longitude))
感谢@КириллМалышев,节省了4个字节
@Rod节省了21个字节
from requests import*;print(get('http://su0.ru/auls').text.split(',')[5:7])
from requests import*;print(get('http://ip-api.com/json').text.split(',')[5:7])就足够了
Add-Type -A System.Device;($a=[Device.Location.GeoCoordinateWatcher]::new()).Start();for(;($b=$a|% Po*n|% L*)|% I*){}$b|select L*e
取消高尔夫:
Add-Type -AssemblyName System.Device #Required to access System.Device.Location namespace
$GeoWatcher = New-Object System.Device.Location.GeoCoordinateWatcher #Create the required object
$GeoWatcher.Start() #Begin resolving current locaton
whille ($GeoWatcher.Status -ne "Ready") do { sleep -Milliseconds 100 } #Wait for discovery.
$GeoWatcher.Position.Location | Select Latitude,Longitude #Select the relevent results.
返回为:
PS C:\users\sweeneyc\Desktop> Add-Type -A System.Device;($a=[Device.Location.GeoCoordinateWatcher]::new()).Start();for(;($b=$a|% Po*n|% L*)|% I*){}$b|select L*e
Latitude Longitude
-------- ---------
53.4064177191653 -6.36202495701332
事实证明,有一种方法可以做到这一点,但它并不那么漂亮。
奖励:在您当前的位置打开Google地图。
Add-Type -A System.Device;($a=[Device.Location.GeoCoordinateWatcher]::new()).Start();for(;($b=$a|% Po*n|% L*)|% I*){};saps "https://www.google.ie/maps/@$($b.Latitude),$($b.Longitude)z"
可以使用节省3个字节,TryStart但它true会向管道输出a 并花费更多的钱来抑制这种情况。
Add-Type -A System.Device;($a=[Device.Location.GeoCoordinateWatcher]::new()).TryStart($true,[int]9e8);$a|% Po*n|% L*|select L*e
(irm freegeoip.net/xml).Response|select *ude
由于PowerShell没有用于“当前位置”的内部内置程序,因此使用外部服务-这是基于IP的地理位置,因此几乎可以肯定不会返回您的实际位置,它将为您的ISP返回一个“默认”位置,并且如果您运行无论退出点在哪里,都可以通过VPN看到。
我已经尝试过(不是作为高尔夫运动)让Google Maps API与wireless-mac-address geolocation方法一起使用,但是它远非精确或可高尔夫使用。
由于结果不准确而被标记为非竞争。
PS C:\Users\sweeneyc> (irm freegeoip.net/xml).Response|select *ude
Latitude Longitude
-------- ---------
53.3472 -6.2439
Central Dublin, Ireland搜寻时会显示此信息,但是目前我离市中心有点远,离返回点约8英里。
GeoCoordinateWatcher一种TryStart方法,该方法看起来像在状态为Ready而不是在其上循环时返回。如果该方法明显可用。
true在输出lat / long之前将其转储到管道中,并且我认为它可能违反了输出时的规范。
[int]9e8在您设置超时时在部分上节省一个字节,TryStart但是我无法使用它,9999999并且[int]9e8与添加额外的9相同
❦™navigator.geolocation.getCurrentPosition#x=>™alert##y=x.coords▷.latitude+","+y.longitude▷▷●
❦ Define an IIFE
™ Get the scope
navigator Get JavaScript's navigator object from the scope
geolocation Get the geolocation property of the navigator object
getCurrentPosition Get the current position and execute a function
x=> Define a function with x as a parameter
™ Get the scope
alert Call alert and alert the following string:
#y=x.coords▷ Define y with the value of the coordinates of x
latitude Get y's latitude
+"," Append "," to the string
+y.longitude Append the longitude to the string
● Close the IIFE and call it with the scope
仅限Windows,Office 2016+供
Microsoft.Mashup.OleDb.1提供程序使用
完整的sub例程,无需输入,并将您的当前位置输出为带Excel.ListObject类型的表格,包括其他信息。
Sub a
ThisWorkbook.Queries.Add"x","let S=Json.Document(Web.Contents(""su0.ru/auls""))in S
With Sheet1.ListObjects.Add(0,"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=x",,,[A1]).QueryTable
.CommandText="SELECT * FROM [x]
.Refresh
End With
End Sub
出于明显原因,排除了示例输出。
-2字节使用的[Sheet1]过Sheets(1)
gl是Get-Location,我认为这C:\Users\Connor不会帮助您逃离森林。