From the course: Code Clinic: C

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Getting geolocation data in C

Getting geolocation data in C - C Tutorial

From the course: Code Clinic: C

Start my 1-month free trial

Getting geolocation data in C

I suppose in the trendier, more popular programming languages, a function or method is available to grab a device's exact location on planet earth. In those digital tongues, the solution for this challenge would be three lines long if that. Such convenience is impossible at C, which made this particular puzzle most challenging. Further, I wanted to ensure that the code would run on any platform. So, its in text mode obviously that it also relies upon the device's public IP address. From that address, I would query at least three online databases that associate geolocation data with an IP address. That result will give me a best guess location. But its still inaccurate as an IP address isn't location sensitive and definitely not static. Because the code is just querying IP addresses. It really isn't a geolocation program in C as much as it's a C implementation of multiple curl strips. Curls a command line tool that fetches data from webpage addresses. So I knew that once I found the IP…

Contents