简体   繁体   English

如何在Google地图中编辑默认标记

[英]How to edit default marker in google maps

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

If you click on A or B, it will show location name in default marker. 如果单击A或B,它将在默认标记中显示位置名称。 I wish to show some custom texts here. 我希望在这里显示一些自定义文本。 How can I do that? 我怎样才能做到这一点? My JavaScript code for this is: 我的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);
  }
});
}

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM