呃,我在哪里?


26

不好了!我被困在一个大森林里(好吧,不是真的,只是假设一下),我不知道我在哪里!

幸好我带了笔记本电脑。但是,当我搜索“地图”时,它说“没有结果”,我是最后一招。

请制作一个以任何两个数字格式输出我的位置的经度和纬度的程序。any two number format包括:

  • 一个元组。
  • 包含经度和纬度的字符串。
  • JSON对象。
  • 等等..

可以使用任何API或库。也就是说,您可以查询Google Maps等。(我想,他们并没有废弃他们的API:\)


19
PowerShell具有,可悲的glGet-Location,我认为这C:\Users\Connor不会帮助您逃离森林。
colsw

C:\ Users \ @Connor> sudo yes
Matthew

Answers:


72

Mathematica,4个字节

嗯,我在哪里?

Here

评估为GeoPosition[{latitude, longitude}]


5
o_O Mathematica对此有内置功能吗?
马修·卢

4
@SIGSEGV 当然...(摘要4)
Martin Ender

33
Mathematica具有所有功能的内建
元素

10
更好的是:该命令Sunset[Here] - Now正确返回到日落之前的时间。
格雷格·马丁

4
我很高兴看到答案获得的投票比问题多。恭喜👏👏👏
马修卢武铉

11

JavaScript(ES6),89 82字节

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()latitudelongitude属性x.coords。请注意,对象x是在调用回调函数watchPosition()时(即,在检索地理位置数据之后)传递给回调函数的。


注意:如果GPS可用,则地理定位数据基于GPS,否则基于IP。


2
watchPosition而不是getCurrentPosition节省5个字节。alert([(y=x.coords).latitude,y.longitude])保存2个以上
约翰·卡尔森

短1个字符,则引发错误:for(f in r=navigator.geolocation)r=r[f](x=>alert((y=x.coords).latitude+","+y.longitude))
user2428118 '17

3
确实,在JS可以依靠其过长的属性名称而具有竞争力的情况下,确实很少见。
毛茸茸的

@JohanKarlsson谢谢!实现了!
Arjun

@Shaggy True,的确如此。
Arjun

8

Python和请求,101 100 75个字节

感谢@КириллМалышев,节省了4个字节

@Rod节省了21个字节

from requests import*;print(get('http://su0.ru/auls').text.split(',')[5:7])

如果这是Python 2,则可以通过删除括号来节省1个字节
Wondercricket

也许最好使用短网址?例如,su0.ru/auls。这样您将节省4个字节。
КириллМалышев

您不需要所有这些格式,from requests import*;print(get('http://ip-api.com/json').text.split(',')[5:7])就足够了
Rod

链接坏了!如果要使用URL缩短器,最好使用已建立的URL缩短器。
雅各布

5

PowerShell,130字节

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

事实证明,有一种方法可以做到这一点,但它并不那么漂亮。

奖励:在您当前的位置打开Goog​​le地图。

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

PowerShell(非竞争),44字节

(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英里。


在C#中,您可以尝试使用GeoCoordinateWatcher一种TryStart方法,该方法看起来像在状态为Ready而不是在其上循环时返回。如果该方法明显可用。
TheLethalCoder

1
@TheLethalCoder是我研究的第一件事,在示例中添加了此内容,它总共只节省了3个字节,但是true在输出lat / long之前将其转储到管道中,并且我认为它可能违反了输出时的规范。
colsw

@TheLethalCoder可以[int]9e8在您设置超时时在部分上节省一个字节,TryStart但是我无法使用它,9999999并且[int]9e8与添加额外的9相同
。– colsw

2

(非竞争)Angolf110个 107字节

❦™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

1
欢迎光临本站!我似乎找不到有关Angolf的任何信息;您介意链接其网站吗?
ETHproductions's


1
欢迎光临本站!您是否有比这更旧的链接?如果不是,则认为该语言比挑战性新。它是为纪念在语言答案不是与挑战新的自定义(非竞争)的称号
可破坏柠檬

我已经有Angolf三个月了,但我现在将其上传到GitHub,因为它之前没有链接
该用户

@thatoneuser不幸在这个视线语言需要已发布到被标记为“竞合”请不要将其标记为非竞争性(这意味着你可以参加与加纳upvotes,但你会续被认为是公认的标记处。
罗汉Jhunjhunwala

0

C#,132个字节

_=>{var w=new System.Device.Location.GeoCoordinateWatcher();w.Start();var c=w.Position.Location;return c.Longitude+","+c.Latitude;};

0

Excel的VBA(Windows和Office 2016+只),278个 272字节

仅限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)


0

迅速4125个117 96字节

不幸的是,这只能在本地进行测试。

import CoreLocation;var c=CLLocationManager().location!.coordinate;print(c.longitude,c.latitude)
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.