通过从给定纬度移动SOUTH x米数来计算新纬度点的最简单方法是什么?例如,艾菲尔铁塔位于48.8582 latitude and 2.2940 longitude
。我在塔周围有一个半径为171米的圆圈。我想在圆圈下面放置一个InfoBox。
所以这是我的圈子:
var circle = new google.maps.Circle({
map: map,
fillColor: 'red',
fillOpacity: 0.2,
strokeWeight: 1,
center: new google.maps.LatLng(48.8582, 2.2940),
radius: 171
});
我的信息框当前位于圆圈的死点,但我希望它直接位于圆圈下方。所以我猜我只需要向南移动(171/2 = 85.5)米以获得我想要的定位。
这有一个简单的计算方法吗?我查看了haversine formula,但这似乎比我需要的要复杂得多,而且我不明白如何使用它,以及它是否适合这个问题。
我想向南走85.5米并获得新的纬度/长坐标以定位InfoBox。据推测,只有纬度才会改变,但我不确定。
答案 0 :(得分:4)
答案 1 :(得分:3)
您可以使用spherical geometry向南计算171米 computOffset method
google.maps.geometry.spherical.computeOffset(circle.getCenter(),circle.getRadius(),180)
代码段:
var geocoder;
var map;
function initialize() {
var bounds = new google.maps.LatLngBounds();
geocoder = new google.maps.Geocoder();
var secheltLoc = new google.maps.LatLng(-27.532861, 134.693340),
markers,
myMapOptions = {
zoom: 7,
center: secheltLoc,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"), myMapOptions);
var circle = new google.maps.Circle({
map: map,
fillColor: 'red',
fillOpacity: 0.2,
strokeWeight: 1,
center: new google.maps.LatLng(48.8582, 2.2940),
radius: 171
});
map.fitBounds(circle.getBounds());
var boxText = document.createElement("div");
boxText.innerHTML = "Eiffel Tower<br>48.8582 latitude<br> 2.2940 longitude";
// Start InfoBox
//these are the options for all infoboxes
infoboxOptions = {
content: boxText,
disableAutoPan: false,
zIndex: null,
maxWidth: 0,
boxStyle: {
background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/examples/tipbox.gif') no-repeat",
opacity: 0.85
},
closeBoxMargin: "6px 2px 0px 0px",
closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif",
infoBoxClearance: new google.maps.Size(1, 1),
isHidden: false,
pane: "floatPane",
enableEventPropagation: false,
pixelOffset: new google.maps.Size(-50, 0)
};
//define the text and style for all infoboxes
boxText.style.cssText = "width: 100px; border: 1px solid #333; margin-top: 3px; background: #fff; padding: 1px; font-size: 11px; white-space:nowrap; padding-right: 20px; color: #333";
//Define the infobox
var infobox = new InfoBox(infoboxOptions);
infobox.setPosition(google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), 180));
infobox.open(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
#map-canvas {
height: 400px;
width: 400px;
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&ext=.js"></script>
<script src="http://www.staff.org.au/infobox.js"></script>
<div id="map-canvas"></div>