def METHOD_NAME(
    ctx, cli_ob, window, dry_run, verbose_flag, timestamp, theme, **kwargs
):
    """Add missing location data to photos in Photos.app using nearest neighbor.
    This command will search for photos that are missing location data and look
    for the nearest neighbor photo within a given window of time that contains
    location information. If a photo is found within the window of time, the
    location of the nearest neighbor will be used to update the location of the
    photo.
    For example, if you took pictures with your iPhone and also with a camera that
    doesn't have location information, you can use this command to add location
    information to the photos taken with the camera from those taken with the
    iPhone.
    If you have many photos with missing location information but no nearest neighbor
    within the window of time, you could add location information to some photos manually
    then run this command again to add location information to the remaining photos.
    You can specify a subset of photos to update using the query options.  For example,
    `--selected` to update only the selected photos, `--added-after 2020-01-01` to update
    only photos added after Jan 1, 2020, etc.
    Example:
    Add location data to all photos with missing location data within a ±2 hour window:
    `osxphotos add-locations --window "2 hr" --verbose`
    The add-locations command assumes that photos already have the correct date and time.
    If you have photos that are missing both location data and date/time information,
    you can use `osxphotos timewarp` to add date/time information to the photos and then
    use `osxphotos add-locations` to add location information.
    See `osxphotos help timewarp` for more information.
    """
    verbose = verbose_print(verbose_flag, timestamp, theme=theme)
    verbose("Searching for photos with missing location data...")
    try:
        query_options = query_options_from_kwargs(**kwargs)
    except IncompatibleQueryOptions as e:
        echo_error("Incompatible query options")
        echo_error(ctx.obj.group.commands["repl"].get_help(ctx))
        ctx.exit(1)
    photosdb = osxphotos.PhotosDB(verbose=verbose)
    photos = photosdb.query(query_options)
    # sort photos by date
    photos = sorted(photos, key=lambda p: p.date)
    num_photos = len(photos)
    missing_location = 0
    found_location = 0
    verbose(f"Processing {len(photos)} photos, window = ±{window}...")
    with rich_progress(console=get_verbose_console(), mock=verbose_flag) as progress:
        task = progress.add_task(
            f"Processing [num]{num_photos}[/] {pluralize(len(photos), 'photo', 'photos')}, window = ±{window}",
            total=num_photos,
        )
        for idx, photo in enumerate(photos):
            if None in photo.location:
                missing_location += 1
                verbose(
                    f"Processing [filename]{photo.original_filename}[/] ([uuid]{photo.uuid}[/])"
                )
                if neighbor := get_location(photos, idx, window):
                    verbose(
                        f"Adding location {neighbor.location} to [filename]{photo.original_filename}[/] ([uuid]{photo.uuid}[/])"
                        f" from [filename]{neighbor.original_filename}[/] ([uuid]{neighbor.uuid}[/])"
                    )
                    found_location += 1
                    if not dry_run:
                        photoscript.Photo(photo.uuid).location = neighbor.location
                else:
                    verbose(
                        f"No location found for [filename]{photo.original_filename}[/] ([uuid]{photo.uuid}[/])"
                    )
            progress.advance(task)
    echo(
        f"Done. Processed: [num]{num_photos}[/] photos, "
        f"missing location: [num]{missing_location}[/], "
        f"found location: [num]{found_location}[/] "
    )