What you are looking for is the navigation method used by ships and aircraft before the advent of GPS. It requires not only an instrument for measuring the angle between the sun or a star (such as Polaris) and the horizon, but also an accurate time measurement, and charts that can be used to interpret the numbers. And of course an accurate chronometer -- you'll need to know the time at Greenwich Obervatory, in London.
The traditional instrument used for determining this angle is the sextant. Here is an article describing the use of a sextant for deterining one's position:
I suppose that an algorithm for doing what you are asking is available where good sextants are sold - as to the charts, well, perhaps there are downloadable charts somewhere.
Also, here is a good article on determining latitude and longitude by the stars. Latitude is what a sextant will tell you, longitude is determined differently. For that you need two clocks: one set to GMT; one set to your local UTC time (NOT your timezone time). The method is described here: How to Calculate Longitude. Which brings us to the question of how to calculate your local solar time, which is described in this article How to Calculate Solar Time. Clearly you can't use this for navigation - it's convenient for human economics, but not finding your location.
Just to make it clear why you can't use local civil time for determining longitude is that the solar time is nearly the same on both Hawaii and Kodiak islands, but Hawaii's civil time is one hour after Kodiak's. And China stretches some 5,026 kilometers across the East Asian landmass, which is about 4 hours of solar time, but it all has the same civil time.
This question might better be asked in the Sailing SE. Oh, wait, there isn't one, yet.