Geolocation 通过MaxMind数据库将IP映射到纬度和经度

Geolocation 通过MaxMind数据库将IP映射到纬度和经度,geolocation,maxmind,Geolocation,Maxmind,我想通过MaxMind数据库将一组IP地址映射到它们的纬度和经度。我的代码是C语言的,我不知道如何使用这个数据库。我想您可能需要以下内容: #include <stdio.h> #include <GeoIP.h> #include <GeoIPCity.h> int main() { GeoIP *gi; GeoIPRecord *gir; gi = GeoIP_open("/usr/local/share/GeoIP/GeoIP

我想通过MaxMind数据库将一组IP地址映射到它们的纬度和经度。我的代码是C语言的,我不知道如何使用这个数据库。

我想您可能需要以下内容:

#include <stdio.h>
#include <GeoIP.h>
#include <GeoIPCity.h>

int main()
{
    GeoIP *gi;
    GeoIPRecord *gir;

    gi = GeoIP_open("/usr/local/share/GeoIP/GeoIPCity.dat", GEOIP_INDEX_CACHE);

    if (gi == NULL) {
        /* handle error */
    }

    gir = GeoIP_record_by_name(gi, "1.1.1.1");
    if (gir == NULL) {
        /* handle error */
    }

    printf("latitude: %f   longitude: %f", gir->latitude, gir->longitude);
}

谢谢你的回答,当我运行这段代码时,我得到了一个错误,比如:/tmp/ccZD5Cwa.o:在函数main中:geo.c:.text+0x13:对GeoIP的未定义引用打开geo.c:.text+0x28:对“GeoIP_记录_by_name”集合的未定义引用2:ld返回了1个退出状态你是否链接到libGeoIP,例如gcc geo.c-lGeoIP-o geo?也就是说,您可能想考虑使用Python或Perl这样的高级语言。我尝试了以下代码并获得了这个错误:/TMP/CZD5CWA.O:在函数main中:GEO.C:.Text +0x13:未定义的GeiPixOng.C.:.Text +0x28:未定义的引用“GeiPiReCordOn.ByNeNo.COLTECT2: LD返回1退出状态”