/** * Reverse geocoding helper * * @see https://developers.google.com/maps/documentation/javascript/geocoding?hl=FR * @param $value can be a lat,lng format or an address * @param string $type latLng if lat,lng value | address if address value * @param string $precision * @return stdClass */ public static function geocode($value, $type = 'latlng', $precision = 'locality') { $result = new \stdClass(); $data = array('sensor' => 'false', $type => $value, 'language' => \Config::get('app.locale')); $url = self::$googleMapGeocodeUrl . http_build_query($data); $response = Utils::getJSON($url); if ($response->results) { $results = $response->results; if (is_object($results)) { $results[] = $results; } foreach ($results as $key => $value) { if ($type == 'address') { foreach ($value as $k2 => $v2) { $result->{$k2} = $v2; } $result->lat = $value->geometry->location->lat; $result->lng = $value->geometry->location->lng; $result->latLng = $value->geometry->location->lat . ',' . $value->geometry->location->lng; break; } elseif (in_array($precision, $value->types)) { $result->name = $value->formatted_address; foreach ($value->address_components as $keyC => $valueC) { try { $result->{$valueC->types[0]} = $valueC->long_name; } catch (\Exception $e) { } } $result->location = $value->geometry->location->lat . ',' . $value->geometry->location->lng; } } } $result->url = $url; return $result; }
/** * Get a list of available modules from Arx.io * @param array $params * @return array|bool|mixed * @throws \Exception */ public static function getModulesAvailables($params = ['type' => 'array']) { Arr::mergeWithDefaultParams($params); $result = Utils::getJSON('http://www.arx.io/api/v1/modules', true); if ($params['type'] == 'list') { return array_column($result, 'name'); } elseif ($params['type'] == 'infolist') { return array_map(function ($item) { return $item['name'] . ' : ' . $item['description']; }, $result); } return $result; }