How to obtain latitude and longitude of a user by IP address or pinpoint location

后端 未结 2 1133
醉话见心
醉话见心 2021-02-10 13:46

I want to get the geolocation (latitude and longitude) of a computer user by a php script. I was using this one



        
2条回答
  •  萌比男神i
    2021-02-10 14:11

    download geoip.inc - http://www.maxmind.com/download/geoip/api/php-20120410/geoip.inc, geoipcity.inc - http://www.maxmind.com/download/geoip/api/php-20120410/geoipcity.inc, geoipregionvars.php - http://www.maxmind.com/download/geoip/api/php-20120410/geoipregionvars.php,

    GeoLiteCity.dat - http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz please convert GeoLiteCity.dat.gz to GeoLiteCity.dat and put in geoip named folder

        include("application/libraries/geoip/geoipcity.inc");
        include("application/libraries/geoip/geoipregionvars.php");
    
        $giCity = geoip_open("application/libraries/geoip/GeoLiteCity.dat", GEOIP_STANDARD);
    
        $ip =$_SERVER['REMOTE_ADDR'];
        $record = geoip_record_by_addr($giCity, $ip);
    
        echo "Getting Country and City detail by IP Address 

    "; echo "IP: " . $ip . "

    "; echo "Country Code: " . $record->country_code . "
    " . "Country Code3: " . $record->country_code . "
    " . "Country Name: " . $record->country_name . "
    " . "Region Code: " . $record->region . "
    " . "Region Name: " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "
    " . "City: " . $record->city . "
    " . "Postal Code: " . $record->postal_code . "
    " . "Latitude: " . $record->latitude . "<`enter code here`br />" . "Longitude: " . $record->longitude . "
    " . "Metro Code: " . $record->metro_code . "
    " . "Area Code: " . $record->area_code . "
    " ;

提交回复
热议问题