4 require_once(dirname(dirname(__FILE__)).'/settings/settings.php');
5 require_once(CONST_BasePath.'/lib/init-cmd.php');
6 require_once(CONST_BasePath.'/lib/Geocode.php');
7 ini_set('memory_limit', '800M');
10 "Query database from command line. Returns search result as JSON.",
11 array('help', 'h', 0, 1, 0, 0, false, 'Show Help'),
12 array('quiet', 'q', 0, 1, 0, 0, 'bool', 'Quiet output'),
13 array('verbose', 'v', 0, 1, 0, 0, 'bool', 'Verbose output'),
15 array('search', '', 0, 1, 1, 1, 'string', 'Search for given term or coordinate'),
17 array('accept-language', '', 0, 1, 1, 1, 'string', 'Preferred language order for showing search results'),
18 array('bounded', '', 0, 1, 0, 0, 'bool', 'Restrict results to given viewbox'),
19 array('nodedupe', '', 0, 1, 0, 0, 'bool', 'Do not remove duplicate results'),
20 array('limit', '', 0, 1, 1, 1, 'int', 'Maximum number of results returned (default: 10)'),
21 array('exclude_place_ids', '', 0, 1, 1, 1, 'string', 'Comma-separated list of place ids to exclude from results'),
22 array('featureType', '', 0, 1, 1, 1, 'string', 'Restrict results to certain features (country, state,city,settlement)'),
23 array('countrycodes', '', 0, 1, 1, 1, 'string', 'Comma-separated list of countries to restrict search to'),
24 array('viewbox', '', 0, 1, 1, 1, 'string', 'Prefer results in given view box')
26 getCmdOpt($_SERVER['argv'], $aCMDOptions, $aCMDResult, true, true);
30 if (isset($aCMDResult['search']) && $aCMDResult['search'])
32 if (isset($aCMDResult['bounded'])) $aCMDResult['bounded'] = 'true';
33 if (isset($aCMDResult['nodedupe'])) $aCMDResult['dedupe'] = 'false';
35 $oGeocode = new Geocode($oDB);
36 if (isset($aCMDResult['accept-language']) && $aCMDResult['accept-language'])
37 $oGeocode->setLanguagePreference(getPreferredLanguages($aCMDResult['accept-language']));
39 $oGeocode->setLanguagePreference(getPreferredLanguages());
40 $oGeocode->loadParamArray($aCMDResult);
41 $oGeocode->setQuery($aCMDResult['search']);
43 $aSearchResults = $oGeocode->lookup();
45 if (version_compare(phpversion(), "5.4.0", '<'))
46 echo json_encode($aSearchResults);
48 echo json_encode($aSearchResults, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)."\n";
52 showUsage($aCMDOptions, true);