Get approximate location from IP

This is a simple (Windows) function that returns the latitude and longitude determined from your IP address by looking up up at

Not as good as being able to use e.g. browser location data which is pretty accurate however I haven't figured how to do that in Igor, yet....

Should work in all versions of Igor that run on Windows for as far back as the ExecuteScriptText command goes. On Mac I'm sure there is an easy modification. 

// funtion to get the approximate location of the computer from the IP address
Function [Variable latitude, Variable Longitude] getApproximateLocation()

    Variable i
    String linestr
    ExecuteScriptText/B/Z "cmd.exe /C curl" //

        LineStr = StringFromList(i,S_value, "\n")
        // Success
        if (Stringmatch(lineStr,"*loc*"))
            sscanf lineStr, "   \"loc\": \"%f,%f\",", latitude, longitude
    while (i < ItemsInList(S_value, "\n")) 
    return [latitude, longitude]


You can use the built-in FetchURL function instead of ExecuteScriptText. That's been available since Igor 6.something (6.3 IIRC). However we only started supporting the https:// scheme in Igor 7, and it appears that always redirects to https, so you can't use IP6 at that site. But even with IP8 the string returned by the server doesn't contain the location information (I think that requires javascript to be executed, which curl can't do).

A Google search for "free geolocation api" turned up Their service works with IP6 and later:


print fetchurl("")

Igor does not have a documented json parser, but the json returned by this query is simple enough to parse using regular text commands.

Here is a more neat solution:

// function to get the approximate location of the computer and UTC offset from the IP address
Function [Variable latVar,Variable lonVar,Variable offVar] getApproxLocationTimeZone()
    String rtnStr = fetchurl(",lat,lon,offset&quot;)
    latVar = NumberByKey("\"lat\"",rtnStr,":",",") 
    lonVar = NumberByKey("\"lon\"",rtnStr,":",",")
    offVar = NumberByKey("\"offset\"",rtnStr,":",",")
    return [latVar,lonVar,offVar]





Igor Pro 9

Learn More

Igor XOP Toolkit

Learn More

Igor NIDAQ Tools MX

Learn More