구글 맵스 API를 사용하여 3, 나는 클릭 이벤트와 폴리 라인을했습니다. 사용자가 클릭 한 경로의 두 지점을 알아야합니다. 포인트의 인덱스가 이상적입니다.구글 맵 폴리 라인 포인트 사이를 클릭하십시오
다음은 대부분 Google 문서에서 직접 가져온 샘플 페이지이지만 click 이벤트가 추가되었습니다. 실제 앱에는 훨씬 복잡한 폴리 라인이 있습니다.
이렇게하는 방법이 있습니까?
많은 감사
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Polylines</title>
<style>
#map {
height: 100%;
}
/* Optional: Makes the sample page fill the window. */
html, body {
height: 100%;
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: {lat: 0, lng: -180},
mapTypeId: 'terrain'
});
var flightPlanCoordinates = [
{lat: 37.772, lng: -122.214},
{lat: 21.291, lng: -157.821},
{lat: -18.142, lng: 178.431},
{lat: -27.467, lng: 153.027}
];
var poly = new google.maps.Polyline({
path: flightPlanCoordinates,
geodesic: true,
strokeColor: '#FF0000',
strokeOpacity: 1.0,
strokeWeight: 2
});
poly.setMap(map);
google.maps.event.addListener(poly, 'click', function(e) {
alert(JSON.stringify(e));
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEY&callback=initMap">
</script>
나는이 길을 시작했지만, 컷백 도로가있을 때 문제가 발생합니다. "가장 가까운"지점은 경로상의 해당 지점에 실제로 있지 않은 도로에있을 수 있습니다. –