鉴于你在地图上定义了这个圆圈,你将如何获得以给定角度相交的点的LatLong?
var degrees = 90;
var center = {lat: 34.052235, lng: -118.243683};
var circle = new google.maps.Circle({
center: center,
radius: 500000
});
var pointOnCircle = ?
答案 0 :(得分:1)
您可以使用geometry library computeOffset
方法:
var pointOnCircle = google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), degrees);
代码段
function initialize() {
var map = new google.maps.Map(
document.getElementById("map_canvas"), {
center: new google.maps.LatLng(37.4419, -122.1419),
zoom: 13,
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var degrees = 90;
var center = {
lat: 34.052235,
lng: -118.243683
};
var circle = new google.maps.Circle({
center: center,
radius: 500000,
map: map
});
map.fitBounds(circle.getBounds());
var pointOnCircle = google.maps.geometry.spherical.computeOffset(circle.getCenter(), circle.getRadius(), degrees);
var marker = new google.maps.Marker({
map: map,
position: pointOnCircle
});
var polyline = new google.maps.Polyline({
map: map,
path: [circle.getCenter(), pointOnCircle]
})
}
google.maps.event.addDomListener(window, "load", initialize);

html,
body,
#map_canvas {
height: 100%;
width: 100%;
margin: 0px;
padding: 0px
}

<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry"></script>
<div id="map_canvas"></div>
&#13;