0

请检查此地图视图: http: //gmaps-samples-v3.googlecode.com/svn/trunk/map_language/map_lang.html

如果您单击 A 或 B,它将在默认标记中显示位置名称。我希望在这里展示一些自定义文本。我怎样才能做到这一点?我的 JavaScript 代码是:

var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var map;
var oldDirections = [];
var currentDirections = null;


//getting latitude and longitude from address
var latitude;
var longitude;



var geocoder = new google.maps.Geocoder();
var address = "Downtown Berkeley";
geocoder.geocode( { "address": address}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK)
  {
      // do something with the geocoded result
      //
      latitude = results[0].geometry.location.lat()
      longitude = results[0].geometry.location.lng()
      alert(latitude )
  }
});

//map initialize    

function initialize() {
var myOptions = {
  zoom: 13,
  center: new google.maps.LatLng(-33.879,151.235),
  mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

//adding marker 
var marker = new google.maps.Marker
    (
        {
            position: new google.maps.LatLng(latitude , longitude),
            map: map,
            title: "Click me"
        }
    );
    var infowindow = new google.maps.InfoWindow({
        content: "Location info:<br/>Country Name:<br/>LatLng:"
    });
    google.maps.event.addListener(marker, "click", function () {
        // Calling the open method of the infoWindow 
        infowindow.open(map, marker);
    });


directionsDisplay = new google.maps.DirectionsRenderer({
    "map": map,
    "preserveViewport": true,
    "draggable": true

});
directionsDisplay.setPanel(document.getElementById("directions_panel"));

google.maps.event.addListener(directionsDisplay, "directions_changed",
  function() {
    if (currentDirections) {
      oldDirections.push(currentDirections);

    }
    currentDirections = directionsDisplay.getDirections();

  });



calcRoute();
}

function calcRoute() {
var start = "El Cerrito del Norte";
var end = "Downtown Berkeley";
var request = {
    origin:start,
    destination:end,
    travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
  if (status == google.maps.DirectionsStatus.OK) {
    directionsDisplay.setDirections(response);
  }
});
}
4

1 回答 1

0

您在 createInfoWindow() 方法中设置该内容。

于 2013-02-25T15:44:37.760 回答