ルート検索の吹き出しを変更する



Code

<script type='text/javascript'>

var mapCanvas;
function initialize() {
  var myOptions = {
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };
  mapCanvas = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
  
  var rendererOptions = {
    map: mapCanvas
  };
  var directionsDisplay = new google.maps.DirectionsRenderer(rendererOptions)
  
  var request = { 
    origin: "東京駅", 
    destination: "大阪駅", 
    travelMode: google.maps.DirectionsTravelMode.DRIVING 
  };
  
  directionsService = new google.maps.DirectionsService();
  directionsService.route(request, function(response, status) {
    if (status == google.maps.DirectionsStatus.OK) {
      var route = response.routes[0];
      mapCanvas.fitBounds(route.bounds);
      
      route.legs[0].start_address = "<b>出発地点</b><br><br>JR東京駅<br>(" + route.legs[0].start_address + ")";
      route.legs[0].end_address = "<b>執着地点</b><br><br>JR大阪駅<br>(" + route.legs[0].end_address + ")";
      directionsDisplay.setDirections(response);
    }
  });
}
google.maps.event.addDomListener(window, "load", initialize);
</script>

Search
Books
Google Maps API Programming Guide

Four Google Maps API Experts wrote this book. Introducing useful examples for developers!
See more details