# 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 – juan Oct 15 '11 at 14:05

## 4 Answers

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$.

Note : R is the radius of your sphere.

• 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

I ended up using what's in this page

Destination point given distance and bearing from start point

Formula:
lat2 = asin(sin(lat1)*cos(d/R) + cos(lat1)*sin(d/R)*cos(θ))
lon2 = lon1 + atan2(sin(θ)*sin(d/R)*cos(lat1), cos(d/R)−sin(lat1)*sin(lat2))

θ is the bearing (in radians, clockwise from north); d/R is the angular distance (in radians), where d is the distance travelled and R is the earth’s radius

For θ I used -45 degrees (in radians) for point B and 135 degrees for point C

• You probably mean 135 degrees for point C. – robjohn Oct 13 '11 at 19:54