setcookie() issues on running with HTTPS on WordPress

Both examples should work fine if your WordPress site is running on https://.

However, I would recommend you set up the cookies by using available constants and functions provided by WordPress, it makes things more organized. See example below:

setcookie( 'lat', sanitize_text_field( $_POST['lat'] ), strtotime( '+14 days' ), "https://wordpress.stackexchange.com/", esc_COOKIE_DOMAIN, is_ssl(), true );

Notice that I’m using is_ssl to check whether the site is running on https or not. This should work fine.

Also, don’t insert any data coming from your web server environment without filtering it, always secure yourself.