Android Find Latitude Longitude X points from a given location

im is working on Android MapView and is developing a map based application. I need to find the distance X from a specific Co-ordinates . Destination is not my priority. Distance is my priority. Let's say I need to find 100 meters from a specific place, any idea on how I can do this Thank you in advance for reading and responding.

+4
source share
2 answers

in order to calculate, to find a point on a line at a given distance from the origin, you need to have a bearing (or direction), as well as a distance. Here is a function that will take the initial location, bearing and distance (depth) and return the destination (for Android): you can convert it from KM to meters or something else.

 public static Location GetDestinationPoint(Location startLoc, float bearing, float depth) { Location newLocation = new Location("newLocation"); double radius = 6371.0; // earth mean radius in km double lat1 = Math.toRadians(startLoc.getLatitude()); double lng1 = Math.toRadians(startLoc.getLongitude()); double brng = Math.toRadians(bearing); double lat2 = Math.asin( Math.sin(lat1)*Math.cos(depth/radius) + Math.cos(lat1)*Math.sin(depth/radius)*Math.cos(brng) ); double lng2 = lng1 + Math.atan2(Math.sin(brng)*Math.sin(depth/radius)*Math.cos(lat1), Math.cos(depth/radius)-Math.sin(lat1)*Math.sin(lat2)); lng2 = (lng2+Math.PI)%(2*Math.PI) - Math.PI; // normalize to -180...+180 if (lat2 == 0 || lng2 == 0) { newLocation.setLatitude(0.0); newLocation.setLongitude(0.0); } else { newLocation.setLatitude(Math.toDegrees(lat2)); newLocation.setLongitude(Math.toDegrees(lng2)); } return newLocation; }; 
+7
source

Just to answer from the javre to meters and radians instead of degrees.

 /** * Create a new location specified in meters and bearing from a previous location. * @param startLoc from where * @param bearing which direction, in radians from north * @param distance meters from startLoc * @return a new location */ public static Location createLocation(Location startLoc, double bearing, double distance) { Location newLocation = new Location("newLocation"); double radius = 6371000.0; // earth mean radius in m double lat1 = Math.toRadians(startLoc.getLatitude()); double lng1 = Math.toRadians(startLoc.getLongitude()); double lat2 = Math.asin(Math.sin(lat1) * Math.cos(distance / radius) + Math.cos(lat1) * Math.sin(distance / radius) * Math.cos(bearing)); double lng2 = lng1 + Math.atan2(Math.sin(bearing) * Math.sin(distance / radius) * Math.cos(lat1), Math.cos(distance / radius) - Math.sin(lat1) * Math.sin(lat2)); lng2 = (lng2 + Math.PI) % (2 * Math.PI) - Math.PI; // normalize to -180...+180 if (lat2 == 0 || lng2 == 0) { newLocation.setLatitude(0.0); newLocation.setLongitude(0.0); } else { newLocation.setLatitude(Math.toDegrees(lat2)); newLocation.setLongitude(Math.toDegrees(lng2)); } return newLocation; } 
+1
source

All Articles