This is an example code to do the same thing as I said in comment using a console CppWinRT project.
#include "pch.h"
#include <winrt/Windows.Devices.Geolocation.h>
using namespace winrt;
using namespace Windows::Foundation;
using namespace winrt::Windows::Devices::Geolocation;
int main()
{
init_apartment();
Uri uri(L"http://aka.ms/cppwinrt");
printf("Hello, %ls!\n", uri.AbsoluteUri().c_str());
// Create geolocator object
Geolocator geolocator;
auto operation = geolocator.GetGeopositionAsync();
switch (operation.wait_for(TimeSpan(50000000)))
{
case AsyncStatus::Completed:
printf("result %d\n", operation.GetResults());
break;
case AsyncStatus::Canceled:
puts("canceled");
break;
case AsyncStatus::Error:
{
winrt::hresult h = operation.ErrorCode();
puts("failed");
}
break;
case AsyncStatus::Started:
puts("still running");
break;
}
// Make the request for the current position
auto status = geolocator.LocationStatus();
}