PowerShell ขนาด 130 ไบต์
Add-Type -A System.Device;($a=[Device.Location.GeoCoordinateWatcher]::new()).Start();for(;($b=$a|% Po*n|% L*)|% I*){}$b|select L*e
Ungolfed:
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
ไปยังไปป์ไลน์และมีค่าใช้จ่ายมากขึ้นในการปราบปราม
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 ไม่มี builtins ภายในสำหรับ 'ตำแหน่งปัจจุบัน' - นี่คือตำแหน่งทางภูมิศาสตร์ที่ใช้ IP ดังนั้นเกือบจะไม่ส่งคืนตำแหน่งที่แท้จริงของคุณแน่นอนมันจะส่งคืนตำแหน่ง 'เริ่มต้น' สำหรับ ISP ของคุณและถ้าคุณเรียกใช้ สิ่งนี้ผ่าน VPN จะปรากฏขึ้นทุกที่ที่มีทางออก
ฉันพยายาม (ไม่ใช่แบบฝึกหัดกอล์ฟ) เพื่อให้ Google Maps API ทำงานร่วมกับวิธีระบุตำแหน่งทางภูมิศาสตร์แบบไร้สาย - แมคที่อยู่ แต่ก็ยังห่างไกลจากความถูกต้องหรือเล่นได้
ทำเครื่องหมายว่าไม่ใช่การแข่งขันเนื่องจากความไม่ถูกต้องของผลลัพธ์
PS C:\Users\sweeneyc> (irm freegeoip.net/xml).Response|select *ude
Latitude Longitude
-------- ---------
53.3472 -6.2439
สิ่งนี้จะปรากฏขึ้นCentral Dublin, Ireland
เมื่อทำการค้นหาอย่างไรก็ตามฉันกำลังออกไปนอกตัวเมืองเล็กน้อยประมาณ 8 ไมล์จากจุดที่ส่งคืน
gl
ไว้เพื่อGet-Location
เศร้าที่ฉันไม่คิดว่าC:\Users\Connor
จะช่วยให้คุณหลบหนีจากป่ามาก