Geocoding into rectangular coordinates

Given the input, central latitude, average longitude, and radius in kilometers, I want to get the coordinates for the rectangle that contains this circle (northeast and southwest lat / lng).

Do I have to write a method myself? Although I'm afraid not to take into account some things, since my math is rusty. Or can I find a ready-made implementation for java? I have google maps sdk in my project, but I did not find anything useful there.

+1
source share
1 answer

I believe that your square radius is much smaller than the radius of the earth (6371 km) so that you can safely ignore the curvature of the earth.

Then the math is pretty simple:

// center of square double latitudeCenter = ...; // in degrees double longitudeCenter = ...; // in degrees double radius = ...; // in km double RADIUS_EARTH = 6371; // in km // north-east corner of square double latitudeNE = latitudeCenter + Math.toDegrees(radius / RADIUS_EARTH); double longitudeNE = longitudeCenter + Math.toDegrees(radius / RADIUS_EARTH / Math.cos(Math.toRadians(latitudeCenter))); // south-west corner of square double latitudeSW = latitudeCenter - Math.toDegrees(radius / RADIUS_EARTH); double longitudeSW = longitudeCenter - Math.toDegrees(radius / RADIUS_EARTH / Math.cos(Math.toRadians(latitudeCenter))); 

Example:

Center (lat, bosom) at 48.00,11.00 and a radius of 10 km
will give the NE-angle (lat, lon) at 48.09,11.13 and the SW-angle (lat, lon) at 47.91,10.87 .

And here's how to do it using LatLng and the Bounds API google-maps-services-java :

 public static final double RADIUS_EARTH = 6371; public static Bounds boundsOfCircle(LatLng center, double radius) { Bounds bounds = new Bounds(); double deltaLat = Math.toDegrees(radius / RADIUS_EARTH); double deltaLng = Math.toDegrees(radius / RADIUS_EARTH / Math.cos(Math.toRadians(center.lat))); bounds.northeast = new LatLng(center.lat + deltaLat, center.lng + deltaLng); bounds.southwest = new LatLng(center.lat - deltaLat, center.lng - deltaLng); return bounds; } 
+3
source

All Articles