# How can I get a square starting with a latitude and longitude point?

Is there a formula that given one latitude/longitude point and a radius (in kilometers ideally) would give me a square around the center?

A picture is worth some quantity of words:

I have the latitude/longitude value of point A, and I have D in kilometers; how can I get point B and C in latitude/longitude values?

-
This question is a duplicate of the recently asked (and answered) question on the GIS site at gis.stackexchange.com/q/15545. – whuber Oct 14 '11 at 20:10
Thanks @whuber, I added my answer there as well – juanformoso Oct 15 '11 at 14:05

For a small square on a spherical earth, $D=R \Delta \phi$ where $R$ is the radius of the earth and $\phi$ is in radians. Also $D=\cos \phi \Delta \lambda$ because the lines of longitude converge as you get closer to the pole. I have ignored the change in latitude over your square, which is why I talk about a small square. It is hard to define a large square on the surface of a sphere, but you could assess the change in latitude first, then do the change in longitude separately at the top and bottom borders and be pretty close. My distances are taken on the surface of the earth, not straight lines between the corners-again not important for small squares.

-
+1 for pointing out the difficulties in making sense of this figure as a "square" and for providing a simple solution. – whuber Oct 14 '11 at 20:12

For the corners of the square, we have this diagram

To get $r$ from $D$ (converted to an angle by dividing the distance by the radius of the sphere), we use $\cos(\frac{\pi}{4})=\frac{\tan(D)}{\tan(r)}$ to get $$\tan(r)=\sqrt{2}\tan(D)\tag{1}$$ Then use the Law of Cosines to get the latitudes of the top and bottom corners $$\sin(lat_1)=\sin(lat)\cos(r)+\cos(lat)\sin(r)/\sqrt{2}\tag{2}$$ $$\sin(lat_2)=\sin(lat)\cos(r)-\cos(lat)\sin(r)/\sqrt{2}\tag{3}$$ Then solve the Law of Cosines to get the differences in longitude of the top and bottom corners $$\cos(\Delta long_1)=\frac{\cos(r)-\sin(lat_1)\sin(lat)}{\cos(lat_1)\cos(lat)}\tag{4}$$ $$\cos(\Delta long_2)=\frac{\cos(r)-\sin(lat_2)\sin(lat)}{\cos(lat_2)\cos(lat)}\tag{5}$$

-

If you mean a "square" on the sphere, you can try the following.

If the horizontal lines of your square are at the same latitude $\phi$ and vertical lines are at the same longitude $\lambda$, you only have to compute the variation of longitude $\Delta \lambda$ and latitude $\Delta \phi$ such as $$\lambda_B = \lambda_A - \Delta\lambda$$ $$\phi_B = \phi_A - \Delta\phi$$

At a given latitude, looking at the chord passing by A and of length egal to D, we have $$2 R \sin(\frac{\Delta\lambda}{2})=D$$ The same can be done for $\Delta\phi$.

-
Except that the lines of longitude are not parallel, so $\Delta \lambda$ depends upon $\phi$ – Ross Millikan Oct 13 '11 at 14:19
Thanks for pointing that out. I am ashamed. – alex_reader Oct 14 '11 at 8:13