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]; }
/** * @param $hcp_id * @return \Illuminate\View\View */ public function view_hcp($hcp_id) { $hcp = HcpImport::get($hcp_id); $message = ""; $geo = null; if ($hcp) { if ($hcp->geo_cache_id) { $geo = GeoCache::get($hcp->geo_cache_id); } else { $message = "this HCP has not been geolocated yet"; } } else { $message = "HCP ID:{$hcp_id} not found"; } return view("data.geolocate", ['hcp' => $hcp, 'geo' => $geo, 'message' => $message, 'api_key' => Geocode::$google_api_key]); }