コード例 #1
0
ファイル: Main.php プロジェクト: RevHealth/hcpFindertest
 /**
  * @param $hcp_id
  * @param Request $request
  * @return \Illuminate\View\View
  */
 public function force_geocode_hcp($hcp_id, Request $request)
 {
     $hcp = HcpImport::get($hcp_id);
     $hcp_address = HcpImport::getGeocodeAddress($hcp);
     $geo = null;
     $geo_address = $request->input('address');
     if ($hcp) {
         $resp = Geocode::geocode($geo_address);
         if ($resp['status'] == 'OK') {
             $id = GeoCache::create(new GeoCache(['address' => $hcp_address, 'geocoded_address' => $geo_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);
             HcpImport::update($hcp_id, ['lat' => $geo->lat, 'lng' => $geo->lng, 'geo_cache_id' => $geo->id, 'geo_address' => $geo->address]);
             $hcp = HcpImport::get($hcp_id);
             $message = "Geolocating succeeded";
         } else {
             $message = "Geolocating failed";
         }
     } else {
         $message = "HCP ID:{$hcp_id} not found";
     }
     return view("data.geolocate", ['hcp' => $hcp, 'geo' => $geo, 'message' => $message, 'api_key' => Geocode::$google_api_key]);
 }
コード例 #2
0
ファイル: GeoCache.php プロジェクト: RevHealth/hcpFindertest
 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];
 }