Esempio n. 1
0
 public static function normalize($thing, $other = null)
 {
     # if an 'other' thing is supplied, normalize the input
     # by creating an array of two elements
     if ($other) {
         $thing = array($thing, $other);
     }
     if (is_string($thing)) {
         $thing = trim($thing);
         $pattern_nbr = '(\\-?[0-9]{1,3}\\.?[0-9]{0,6})';
         $pattern = $pattern_nbr . '[,| ] ?' . $pattern_nbr . '$';
         if (ereg($pattern, $thing) > 0) {
             if (strpos($thing, ',') > 0) {
                 $thing = explode(',', $thing);
             } else {
                 $pos = strpos($thing, ' ');
                 if ($pos > 0) {
                     $thing = array(trim(substr($thing, 0, $pos)), trim(substr($thing, $pos, strlen($thing))));
                 }
             }
             return new LatLng($thing[0], $thing[1]);
         } else {
             $multi_geocoder = new MultiGeocoder();
             $result = $multi_geocoder->geocode($thing);
             if ($result->success) {
                 return $result;
             }
             $msg = 'String "' . $thing . '" cannot be normalized as a LatLng.';
             Geocoder::logger('warning', $msg);
             return new LatLng();
         }
     } elseif (is_array($thing) && count($thing) == 2) {
         return new LatLng($thing[0], $thing[1]);
     } elseif ($thing instanceof LatLng || $thing instanceof GeoLoc) {
         return $thing;
     } elseif ($thing instanceof ActsAsMappable) {
         return $thing->to_lat_lng;
     }
     $msg = 'Mappable::normalize: ';
     $msg .= 'An object of ' . get_class($thing) . ' cannot be normalized ';
     $msg .= 'to a LatLng. We tried interpreting it as an array, string, ';
     $msg .= 'Mappable, etc., but no dice.';
     Geocoder::logger('warning', $msg);
     return new LatLng();
 }
Esempio n. 2
0
 private function auto_geocode_address()
 {
     $auto_geocode_field = $this->auto_geocode_field;
     $address = ${$auto_geocode_field};
     $geo = MultiGeocoder::geocode($address);
     if ($geo->success) {
         ${$lat_column_name} = $geo->lat;
         ${$lng_column_name} = $geo->lng;
     } else {
         $msg = $this->auto_geocode_error_message . ' ';
         $msg .= $address . ' in ' . $auto_geocode_field;
         Geocode::logger('error', $msg);
     }
     return $geo->success;
 }
Esempio n. 3
0
 function multi_geocoder($address)
 {
     return MultiGeocoder::do_geocode($address);
 }