diff --git a/weather.module b/weather.module
index 02e45a7..75368c8 100644
--- a/weather.module
+++ b/weather.module
@@ -298,11 +298,12 @@ function weather_block_view($delta = '') {
       }
       break;
     case 'ip':
-      if (user_access('access content') and isset($_SERVER['REMOTE_ADDR'])) {
+      $ip = ip_address();
+      if (user_access('access content') and !empty($ip)) {
         $timeout = 10;
         // Determine the latitude and longitude based on the IP.
         $url = 'http://api.hostip.info/get_html.php?ip=';
-        $url .= $_SERVER['REMOTE_ADDR'];
+        $url .= $ip;
         $url .= '&position=true';
         $result = weather_download_data($url, $timeout);
         // Extract the latitude and longitude from the result, if successful.
