Bagaimana cara mendapatkan Geolokasi menggunakan PHP-cURL dari Alamat IP?

<?php 

 

if(isset($_POST['submit']))

{

 

    $userIP = $_POST['ip'];

  

 

    $ch = curl_init($apiURL); 

 

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

 

    $apiResponse = curl_exec($ch); 

 

    curl_close($ch); 

 

    $ipData = json_decode($apiResponse, true); 

  

  

    if(!empty($ipData)){ 

        $continent = $ipData['continent'];

        $country_code_alpha2 = $ipData['alpha2'];

        $country_code_alpha3 = $ipData['alpha3'];

        $country_name = $ipData['name'];

        $country_code_numeric = $ipData['country_code'];

        $international_prefix = $ipData['international_prefix'];

        $currency_code = $ipData['currency_code'];

        $latitude = $ipData['geo']['latitude'];

        $longitude = $ipData['geo']['longitude'];

      

        echo 'Continent Name: '.$continent.'<br/>'

        echo 'Country Name: '.$country_name.'<br/>'

        echo 'Country Alpha-2 Code: '.$country_code_alpha2.'<br/>'

        echo 'Country Alpha-3 Code: '.$country_code_alpha3.'<br/>'

        echo 'Country Numeric Code: '.$country_code_numeric.'<br/>'

        echo 'Country International Call Prefix Code: '

                . $international_prefix.'<br/>'

        echo 'Currency Code: '.$currency_code.'<br/>'

        echo 'Latitude: '.$latitude.'<br/>'

        echo 'Longitude: '.$longitude

    }

    else{

        echo 'Not a valid IP';

    }

}

 

?>

 

<!DOCTYPE html>

<html lang="en">

 

<head>

    <meta charset="UTF-8">

    <meta name="viewport" content=

        "width=device-width, initial-scale=1.0">

    <title>Get Location</title>

</head>

 

<body>

    <h1>Get Location Using IP Address</h1>

 

    <form method='post' enctype='multipart/form-data'>

        <label>Give IP address for check location</label>

        <input type='text' name='ip' />

        <input type='submit' value='Submit' name='submit' />

        <a href="index.php">Reset</a>

 

    </form>

</body>

 

</html>