protected function _locate($asyncSave = false) { $country = Wpjb_List_Country::getByCode($this->job_country); $country = trim($country['name']); $addr = array($this->job_location, $this->job_zip_code, $this->job_state, $country); $query = http_build_query(array("address" => join(", ", $addr), "sensor" => "false")); $url = "http://maps.googleapis.com/maps/api/geocode/json?" . $query; $response = wp_remote_get($url); if ($response instanceof WP_Error) { $geo = null; } else { $geo = json_decode($response["body"]); } if (!$geo || $geo->status != "OK") { $this->geo_status = self::GEO_MISSING; $this->geo_latitude = 0; $this->geo_longitude = 0; } elseif ($geo->status == "OK") { $this->geo_status = self::GEO_FOUND; $this->geo_latitude = $geo->results[0]->geometry->location->lat; $this->geo_longitude = $geo->results[0]->geometry->location->lng; } if ($this->id > 0 && $asyncSave) { $job = new Wpjb_Model_Job($this->id); $job->geo_status = $this->geo_status; $job->geo_latitude = $this->geo_latitude; $job->geo_longitude = $this->geo_longitude; $job->_saveGeo(); } }