Advertisement
Guest User

Untitled

a guest
Jan 16th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. JS:
  2. function initMap() {
  3. var pointA = new google.maps.LatLng(51.7519, -1.2578),
  4. pointB = new google.maps.LatLng(50.8429, -0.1313),
  5. pointC = new google.maps.LatLng(51.2029, -0.1403),
  6. myOptions = {
  7. zoom: 7,
  8. center: pointA
  9. },
  10. map = new google.maps.Map(document.getElementById('map-canvas'), myOptions),
  11. // Instantiate a directions service.
  12. directionsService = new google.maps.DirectionsService,
  13. directionsDisplay = new google.maps.DirectionsRenderer({
  14. map: map
  15. }),
  16. markerA = new google.maps.Marker({
  17. position: pointA,
  18. title: "point A",
  19. label: "A",
  20. map: map
  21. }),
  22. markerB = new google.maps.Marker({
  23. position: pointB,
  24. title: "point B",
  25. label: "B",
  26. map: map
  27. }),
  28. markerC = new google.maps.Marker({
  29. position: pointC,
  30. title: "point C",
  31. label: "C",
  32. map: map
  33. });
  34. var circle = new google.maps.Circle({
  35. map: map,
  36. radius: 1000, // 10 miles in metres
  37. fillColor: '#AA0000'
  38. });
  39.  
  40. circle.bindTo('center', markerC, 'position');
  41. // get route from A to B
  42. calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB);
  43.  
  44. }
  45.  
  46. function calculateAndDisplayRoute(directionsService, directionsDisplay, pointA, pointB) {
  47. directionsService.route({
  48. origin: pointA,
  49. destination: pointB,
  50. avoidTolls: true,
  51. avoidHighways: false,
  52. travelMode: google.maps.TravelMode.DRIVING
  53. }, function (response, status) {
  54. if (status == google.maps.DirectionsStatus.OK) {
  55. directionsDisplay.setDirections(response);
  56. } else {
  57. window.alert('Directions request failed due to ' + status);
  58. }
  59. });
  60. }
  61.  
  62. initMap();
  63.  
  64. <div id="map-canvas"></div>
  65.  
  66. html, body {
  67. height: 100%;
  68. margin: 0;
  69. padding: 0;
  70. }
  71. #map-canvas {
  72. height: 100%;
  73. width: 100%;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement