- for param, _ in EXTRADATA_PARAMS:
- if getattr(args, param):
- params[param] = '1'
- if args.lang:
- params['accept-language'] = args.lang
- if args.polygon_output:
- params['polygon_' + args.polygon_output] = '1'
- if args.polygon_threshold:
- params['polygon_threshold'] = args.polygon_threshold
+ details = napi.LookupDetails(address_details=True, # needed for display name
+ geometry_output=args.get_geometry_output(),
+ geometry_simplification=args.polygon_threshold or 0.0)
+
+ result = api.reverse(napi.Point(args.lon, args.lat),
+ REVERSE_MAX_RANKS[max(0, min(18, args.zoom or 18))],
+ args.get_layers(napi.DataLayer.ADDRESS | napi.DataLayer.POI),
+ details)
+
+ if result:
+ output = api_output.format_result(
+ napi.ReverseResults([result]),
+ args.format,
+ {'locales': args.get_locales(api.config.DEFAULT_LANGUAGE),
+ 'extratags': args.extratags,
+ 'namedetails': args.namedetails,
+ 'addressdetails': args.addressdetails})
+ if args.format != 'xml':
+ # reformat the result, so it is pretty-printed
+ json.dump(json.loads(output), sys.stdout, indent=4, ensure_ascii=False)
+ else:
+ sys.stdout.write(output)
+ sys.stdout.write('\n')
+
+ return 0
+
+ LOG.error("Unable to geocode.")
+ return 42