based on
http://www.movable-type.co.uk/scripts/latlong.html,
I have this code, but something is wrong. Final point is not on same
latitude
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=ISO-8859-1">
<meta http-equiv="pragma" content="no-cache">
<title>Insert title here</title>
<style type="text/css">
#map {
width: 1000px;
height: 600px;
top: 20px;
left: 20px;
}
#latlng-control {
background: #ffc;
border: 1px solid #676767;
position: absolute;
top: 100px;
left: 100px;
width: 400px;
height: 40px;
}
</style>
<script type="text/javascript" src="
http://maps.google.com/maps/api/js?
sensor=false"></script>
<script type="text/javascript">
var EarthRadiusMeters = 6371000; // meters
google.maps.LatLng.prototype.DestinationPoint = function (brng, dist)
{
var R = EarthRadiusMeters;
var brng = brng.toRad();
var lat1 = this.lat().toRad(), lon1 = this.lng().toRad();
var lat2 = Math.asin( Math.sin(lat1)*Math.cos(dist/R) +
Math.cos(lat1)*Math.sin(dist/
R)*Math.cos(brng) );
var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(dist/
R)*Math.cos(lat1),
Math.cos(dist/R)-
Math.sin(lat1)*Math.sin(lat2));
return new google.maps.LatLng(lat2.toDeg(), lon2.toDeg());
}
Number.prototype.toRad = function () {
return this * Math.PI / 180;
};
Number.prototype.toDeg = function () {
return this * 180 / Math.PI;
};
var map;
var overlay;
var bounds;
var hundredMeterBounds = new google.maps.LatLngBounds();
function init() {
var centerLatLng = new google.maps.LatLng(45, 0);
map = new google.maps.Map(document.getElementById('map'), {
'zoom' : 8,
'center' : centerLatLng,
'mapTypeId' : google.maps.MapTypeId.ROADMAP
});
var marker = new google.maps.Marker( {
position : centerLatLng,
map : map,
title:"Initial point ["+centerLatLng.lat()+", "+centerLatLng.lng()
+"]"
});
var rightPoint = centerLatLng.DestinationPoint(90, 200*1000);//800
km
var marker2 = new google.maps.Marker( {
position : rightPoint,
map : map,
title:"Final point ["+rightPoint.lat()+", "+rightPoint.lng()+"]"
});
drawLine(centerLatLng,rightPoint,"#FF0000");
var elem = document.getElementById('latlng-control');
elem.innerHTML = ("Initial ["+centerLatLng.lat()+",
"+centerLatLng.lng()+"]"+"<br>"+
"Final ["+rightPoint.lat()+", "+rightPoint.lng()+"]");
}
function drawLine(point1,point2,color){
var flightPlanCoordinates = [point1,point2];
var flightPath = new google.maps.Polyline({
path: flightPlanCoordinates,
strokeColor: color,
strokeOpacity: 1.0,
strokeWeight: 2
});
flightPath.setMap(map);
}
google.maps.event.addDomListener(window, 'load', init);
</script>
</head>
<body>
<div id="map"></div>
<div id="latlng-control"></div>
</body>
</html>