지도를 클릭하면 마커를 가장 가까운 거리에 스냅하려고합니다. 좋은 예가 여기에 있습니다 : http://econym.org.uk/gmap/example_snappath.htm (메인 페이지 : http://econym.org.uk/gmap/snap.htm). 그러나이 예는 Google지도 버전 2 용입니다. v3에서이 작업을 수행 할 수있는 방법이 있습니까?Google지도 V3가 가장 가까운 거리에 스냅
14
A
답변
16
주어진 예제는 방향 검색을 수행 한 다음 첫 번째 위치를 가져 와서 결과를 얻습니다. 그것은 아주 좋은 작동 Revolution42 API v3에서이 "지도는"
var directionsService = new google.maps.DirectionsService();
google.maps.event.addListener(map, 'click', function(event) {
var request = {
origin:event.latLng,
destination:event.latLng,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var marker = new google.maps.Marker({
position: response.routes[0].legs[0].start_location,
map: map,
title:"Hello World!"
});
}
});
});
1
많은 감사 맵의 이름입니다 다음 코드를 사용하여 수행됩니다
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height: 100% }
</style>
<script type="text/javascript"
src="http://maps.googleapis.com/maps/api/js?key=YOU API KEY&sensor=false">
</script>
<script type="text/javascript">
function initialize() {
var myOptions = {
center: new google.maps.LatLng(-34.397, 150.644),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
var directionsService = new google.maps.DirectionsService();
google.maps.event.addListener(map, 'click', function(event) {
var request = {
origin:event.latLng,
destination:event.latLng,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var marker = new google.maps.Marker({
position: response.routes[0].legs[0].start_location,
map: map,
title:"Hello World!"
});
}
});
});
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas" style="width:100%; height:100%"></div>
</body>
</html>
관련 문제
- 1. 가까운 거리에 스냅
- 2. Google지도 가장 가까운 유틸리티 찾기
- 3. 윈폼 - ContextMenuStrip을 - 클릭에서 가까운 거리에
- 4. Google지도 크롬에서 V3가 괜찮습니까? 모바일 사파리에서 공백이
- 5. Google지도 api v2 -지도에서 가장 가까운/가장 가까운 마커/점을 찾으시겠습니까?
- 6. GeoIP 가장 가까운 국가 (가장 가까운 국가)
- 7. JQuery와 Google지도 V3가 - 정보 창은 항상 하나 개의 마커 아래
- 8. 마커를 클릭하면 Google지도 v3가 마지막 정보창을 엽니 다.
- 9. 주소에 가장 가까운 교차로를 찾는 방법이 있습니까?
- 10. 라빈의 가장 가까운 이웃 (가장 가까운 점 쌍) 알고리즘?
- 11. 가장 가까운 이웃까지의 평균 거리는 대략입니까?
- 12. MySQL 쿼리로 가장 가까운 수치 선택
- 13. 가장 가까운 마커에 붙이기
- 14. 가장 가까운 분수 근사치
- 15. 가장 가까운 벡터를 찾으십시오
- 16. "가장 가까운 이웃"MATLAB
- 17. jQuery를 가장 가까운 반환
- 18. 가장 가까운 정수로 반올림
- 19. 가장 가까운 숫자를 반올림하십시오.
- 20. 가장 가까운 5로 반올림
- 21. VB.net 가장 가까운 컨트롤
- 22. 가장 가까운 CCSprite 찾기
- 23. 가장 가까운 점을 계산하는 효율적인 방법은 무엇입니까?
- 24. Google지도 API (Lat Lon에 가까운 위치 얻기)
- 25. 구글지도의 V3가 JQuery와
- 26. 가장 가까운 소수를 찾으려면 어떻게해야합니까?
- 27. 가장 가까운 해밍 거리를 찾는다.
- 28. 가장 가까운 주석 얻기 MKMapKit
- 29. Dijkstra의 가장 가까운 이웃 확인
- 30. 주어진 점에 가장 가까운 점