-1

我只是想知道,如何在坐标(38.0,-98.0)上添加一个标记,在坐标(45.0,-100.0)上添加另一个标记到我正在制作的自定义谷歌地图?到目前为止,这是我拥有的代码:

<script type="text/javascript">

  var map;
  var grayStyles = [
    {
      featureType: "all",
      stylers: [
        { saturation: -100 },
      ]
    },
  ];
  var mapOptions = {
    center: new google.maps.LatLng(38, -98),
    zoom: 5,
    styles: grayStyles,
    mapTypeId: google.maps.MapTypeId.ROADMAP
  };

  function initialize() {
    map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
  }

</script>
4

2 回答 2

2

简单的标记:

var marker1 = new google.maps.Marker({
      position: new google.maps.LatLng(38.0, -98.0),
      map: map,
  });

var marker2 = new google.maps.Marker({
      position: new google.maps.LatLng(45.0, -100.0),
      map: map,
  });
于 2013-02-21T01:01:47.723 回答
0

这是我使用的代码,放在该行之后

map = new google.maps.Map(documen......

您可以多次重复此代码以获得更多标记

  var ncenter = new google.maps.LatLng(parseFloat('52.43598') , parseFloat('16.94412'));  /* this is the position */ 
  var image = {
    url: '/img/xspot.png',
    // This marker is 20 pixels wide by 32 pixels tall.
    size: new google.maps.Size(115, 86),
    // The origin for this image is 0,0.
    origin: new google.maps.Point(0,0),
    // The anchor for this image is the base of the flagpole at 0,32.
    anchor: new google.maps.Point(57, 71)
  }; /* You can ignore the image mark */ 
  var beachMarker = new google.maps.Marker({
      position: ncenter,
      map: map,
      icon: image // if you ignore image related code above, also remove this line
  });
于 2013-02-21T00:57:16.870 回答