Exemple #1
0
 public static function findByAddressOrCreateWithNewnessIndicator($address)
 {
     $geo = GeoCache::getByAddress($address);
     $cached = false;
     Log::debug("Found Geocode Object", ["geo_cache" => $geo]);
     if (!$geo) {
         Log::debug('Address NOT found in geo_cache');
         $resp = Geocode::geocode($address);
         $status = $resp['status'];
         if ($status == 'OK') {
             $id = GeoCache::create(new GeoCache(['address' => $address, 'geocoded_address' => $address, 'lat' => $resp['results'][0]['geometry']['location']['lat'], 'lng' => $resp['results'][0]['geometry']['location']['lng'], 'formatted_address' => $resp['results'][0]['formatted_address'], 'location_type' => $resp['results'][0]['geometry']['location_type'], 'partial_match' => Geocode::getPartialMatchFromResponse($resp)]));
             $geo = GeoCache::get($id);
         } else {
             Log::error('geocoding failed', ['address' => $address, 'response' => $resp]);
         }
     } else {
         Log::debug('Address found in geo_cache');
         $cached = true;
         $status = "LOCALLY_CACHED";
     }
     return [$geo, $cached, $status];
 }
Exemple #2
0
 /**
  * @param $id
  * @param Request $request
  * @return \Illuminate\View\View
  */
 public function update_geocache($id, Request $request)
 {
     $address = $request->input('address');
     $hcp_id = $request->input('hcp_id');
     $resp = Geocode::geocode($address);
     if ($resp['status'] == 'OK') {
         GeoCache::update($id, ['geocoded_address' => $address, 'lat' => $resp['results'][0]['geometry']['location']['lat'], 'lng' => $resp['results'][0]['geometry']['location']['lng'], 'formatted_address' => $resp['results'][0]['formatted_address'], 'location_type' => $resp['results'][0]['geometry']['location_type'], 'partial_match' => Geocode::getPartialMatchFromResponse($resp)]);
     } else {
         Log::error('geocoding failed', ['address' => $address, 'response' => $resp]);
     }
     return $this->geocode_hcp($hcp_id);
 }