How do I find the lat/long that is x km north of a given lat/long?

前端 未结 7 1115
花落未央
花落未央 2020-11-30 03:48

I have some C# code that generates google maps. This codes looks at all the Points I need to plot on the map and then works out the Bounds of a rectangle to include those po

7条回答
  •  余生分开走
    2020-11-30 04:36

    For people who want a java version Eirch's code

    /**
     * move latlng point by rang and bearing
     *
     * @param latLng  point
     * @param range   range in meters
     * @param bearing bearing in degrees
     * @return new LatLng
     */
    public static LatLng moveLatLng(LatLng latLng, double range, double bearing) {
        double EarthRadius = 6378137.0;
        double DegreesToRadians = Math.PI / 180.0;
        double RadiansToDegrees = 180.0 / Math.PI;
    
        final double latA = latLng.latitude * DegreesToRadians;
        final double lonA = latLng.longitude * DegreesToRadians;
        final double angularDistance = range / EarthRadius;
        final double trueCourse = bearing * DegreesToRadians;
    
        final double lat = Math.asin(
                Math.sin(latA) * Math.cos(angularDistance) +
                        Math.cos(latA) * Math.sin(angularDistance) * Math.cos(trueCourse));
    
        final double dlon = Math.atan2(
                Math.sin(trueCourse) * Math.sin(angularDistance) * Math.cos(latA),
                Math.cos(angularDistance) - Math.sin(latA) * Math.sin(lat));
    
        final double lon = ((lonA + dlon + Math.PI) % (Math.PI * 2)) - Math.PI;
    
        return new LatLng(lat * RadiansToDegrees, lon * RadiansToDegrees);
    }
    

提交回复
热议问题