要在地图上绘制圆,我有一个中心GLatLng(A)和一个以米为单位的半径(r).
这是一个图表:
-----------
--/ \--
-/ \-
/ \
/ \
/ r \
| *-------------*
\ A / B
\ /
\ /
-\ /-
--\ /--
-----------
Run Code Online (Sandbox Code Playgroud)
如何计算位置B的GLatLng?假设r与赤道平行.
使用GLatLng.distanceFrom()方法获得A和B时的半径是微不足道的 - 但是反过来却不是这样.似乎我需要做一些更重的数学.
您是否可以告诉我是否有可能获得所有地方的列表,例如Google Maps API中的原始路线和目的地之间的加油站?这是一个链接,我试图根据方向支持的路线列出两点之间的所有加油站或休息区(或任何Google Maps API支持的地点类型).
这个我的代码到目前为止:
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var haight = new google.maps.LatLng(49.216364,-122.811897);
var oceanBeach = new google.maps.LatLng(50.131446,-119.506838);
function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom: 14,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: haight
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
directionsDisplay.setMap(map);
calcRoute();
}
function calcRoute() {
var request = {
origin: haight,
destination: oceanBeach,
travelMode: google.maps.TravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
} …Run Code Online (Sandbox Code Playgroud) 我仍然在计算第二点提供的lat/lng和第一点和距离的lat/lng时遇到问题.
我在Javascript中找到了一个解决方案,我试图转换为Java.但结果不准确,似乎我做错了什么.
public class Misc {
double EARTH_RADIUS_METERS= 6378.1 *1024;
private double toRad(double value) {
return value* (Math.PI/ 180);
}
private double toDeg (double value) {
return value* (180 / Math.PI);
}
/*-------------------------------------------------------------------------
* Given a starting lat/lon point on earth, distance (in meters)
* and bearing, calculates destination coordinates lat2/lon2.
*
* all params in radians
*-------------------------------------------------------------------------*/
GPoint destCoordsInRadians(double lat1, double lon1,
double distanceMeters, double bearing
/*,double* lat2, double* lon2*/)
{
//-------------------------------------------------------------------------
// Algorithm from http://www.geomidpoint.com/destination/calculation.html
// Algorithm …Run Code Online (Sandbox Code Playgroud)