# Err, Where am I?

Oh no! I'm trapped in a big forest (Okay, not really, but just assume it) and I don't know where I am!

Thankfully, I brought my laptop. But when I searched 'Maps', It said 'No results', and I'm asking this as a last resort.

Please make a program which outputs my location's longitude and latitude in any two number format. any two number format includes:

• A tuple.
• A string including the longitude and the latitude.
• A JSON Object.
• etc..

Any API or Libraries may be used. That is, You can query Google Maps, etc. (I guess, They didn't trash their APIs :\)

• PowerShell has gl for Get-Location, sadly I don't think C:\Users\Connor will help you escape the forest very much. Commented May 5, 2017 at 8:43
• C:\Users\@Connor>sudo yes Commented May 5, 2017 at 8:47

## Mathematica, 4 bytes

Err, where am I?

Here


Evaluates to GeoPosition[{latitude, longitude}].

• o_O Mathematica had a builtin for this? Commented May 5, 2017 at 8:16
• @SIGSEGV Of course... (snippet #4) Commented May 5, 2017 at 8:17
• Mathematica has a builtin for everything Commented May 5, 2017 at 8:19
• Even better: the command Sunset[Here] - Now correctly returns the amount of time until sunset. Commented May 5, 2017 at 15:57
• I'm amused to see an answer having this more votes than the question. Congrats 👏👏👏 Commented May 6, 2017 at 0:30

# JavaScript (ES6), 89 82 bytes

navigator.geolocation.watchPosition(x=>alert([(y=x.coords).latitude,y.longitude]))


Try it online! (For some reason, this was not working in the snippet).

## Explanation

navigator object is a part of BOM. geolocation is a property of its and is also an object, which contains geolocational data of the user. watchPosition() is a method of geolocation object. It takes in a callback function which is executed after the geolocational data has been retrieved. The callback function x=>alert((y=x.coords).latitude+","+y.longitude) is an anonymous (lambda) function that takes in an object x and alert()s the latitude and longitude properties of x.coords separated by a comma. Note that the object x is passed to the callback function by watchPosition() when the callback function is called (i.e. after the retrieval of the geolocational data).

Note: The geolocational data is GPS-based if GPS is available, otherwise it's based on IP.

• watchPosition instead of getCurrentPosition saves 5 bytes. alert([(y=x.coords).latitude,y.longitude]) saves 2 more Commented May 5, 2017 at 10:56
• 1 character shorter, throws an error: for(f in r=navigator.geolocation)r=r[f](x=>alert((y=x.coords).latitude+","+y.longitude)) Commented May 5, 2017 at 11:14
• It's a rare occasion indeed when JS can be competitive while relying on its overly long property names. Commented May 5, 2017 at 20:04
• @JohanKarlsson Thanks! Implemented it! Commented May 6, 2017 at 14:41
• @Shaggy True, indeed. Commented May 6, 2017 at 14:41

# PowerShell, 130 Bytes

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.


Returns as:

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


Turns out there is a way to do this, but it's not so pretty.

bonus: opens google maps on your current location.

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"  could save 3 bytes using TryStart but it outputs a true to the pipeline and costs more to suppress that. Add-Type -A System.Device;($a=[Device.Location.GeoCoordinateWatcher]::new()).TryStart($true,[int]9e8);$a|% Po*n|% L*|select L*e


# PowerShell (non-competing), 44 Bytes

(irm freegeoip.net/xml).Response|select *ude


Uses an external service since PowerShell has no internal builtins for 'current location' - this is IP-based Geolocation, so almost definitely won't return your actual location, it will return a 'default' location for your ISP, and if you run this over a VPN will present wherever the exit point is.

I've tried (not as a golf exercise) to get google maps API to work with the wireless-mac-address geolocation method, but it's far from accurate or golfable.

marked as non-competing due to the inaccuracy of the results.

PS C:\Users\sweeneyc> (irm freegeoip.net/xml).Response|select *ude
Latitude Longitude
-------- ---------
53.3472  -6.2439


this displays Central Dublin, Ireland when searched up, however i'm a bit outside the city center currently, about 8 miles from the returned point.

• In C# the GeoCoordinateWatcher has a TryStart method which you could try which looks like it returns when the status is Ready instead of looping on it. If that method is available obviously. Commented May 5, 2017 at 13:06
• @TheLethalCoder was the first thing I looked into, added in the example there, it only saves 3 bytes overall, but it dumps a true to the pipeline before I can output the lat/long, and I think it probably violates the spec when that's output. Commented May 5, 2017 at 13:19
• @TheLethalCoder could feasibly save a byte(s) on the [int]9e8 part when you set the timeout in TryStart but i can't get it to work with 9999999 and [int]9e8 is the same as adding an extra 9. Commented May 5, 2017 at 13:21

# Python with requests, 101100 75 bytes

4 bytes saved thanks to @КириллМалышев

21 bytes saved thanks to @Rod

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

• If this is Python 2, you can save 1 byte by removing the parenthesis Commented May 5, 2017 at 16:16
• Maybe it's better to use a short url? For example, su0.ru/auls. So you will save 4 bytes. Commented May 5, 2017 at 17:36
• You don't need all this formatting, from requests import*;print(get('http://ip-api.com/json').text.split(',')[5:7]) should be enough
– Rod
Commented May 5, 2017 at 18:17
• Link is broken! If you're going to use a URL shortener, best to use an established one. Commented Jun 19, 2018 at 4:40

# Angolf, 110 107 bytes

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

• Welcome to the site! I can't seem to find any information about Angolf; would you mind linking its website? Commented May 6, 2017 at 0:11
• github.com/XtremePlayzCODE/angled/blob/master/angolf.js, Sorry for the late reply Commented May 6, 2017 at 0:37

# C#, 132 bytes

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


# Excel VBA (Windows, Office 2016+ Only), 278 272 Bytes

Restricted to Windows, Office 2016+ for the use of the Microsoft.Mashup.OleDb.1 provider

Full subroutine that takes no input and outputs your current location as a Excel.ListObject typed table, including extra information.

Sub a
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


Example output excluded for obvious reasons.

-2 Bytes for use of [Sheet1] over  Sheets(1)

# Swift 4, 125 117 96 bytes

This can only be tested locally, unfortunately.

import CoreLocation;var c=CLLocationManager().location!.coordinate;print(c.longitude,c.latitude)