javascript - 将图像放在 Google map 上

标签 javascript image google-maps

我正在创建一个使用 JavaScript 显示 Google map 的网页。我怎样才能将图像作为图标放在该 map 上。这是我所拥有的:

<script language="javascript">
    var lat=1067;
    var lon=-110;

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.setCenter(new GLatLng(lat, lon), 13);
      }
    }
    function map(position) {
        lat = position.coords.latitude;
        lon = position.coords.longitude;
        load();
    }
    function get_location() {
        navigator.geolocation.getCurrentPosition(map);
    }
    </script>

</head>
<body onload="load()" onunload="GUnload()">
<input type ="Button" size = "50" onclick = "get_location();">Search</input>
<div id="map" style="width: 1200px; height: 600px"></div>

最佳答案

Google map 中的图标是文档中“叠加层”部分的一部分。 Here是文档相关部分的链接。

简而言之:

  var image = 'beachflag.png';
  var myLatLng = new google.maps.LatLng(-33.890542, 151.274856); //or wherever you want the marker placed
  var beachMarker = new google.maps.Marker({
      position: myLatLng,
      map: map,
      icon: image
  });

关于javascript - 将图像放在 Google map 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6413541/

相关文章:

android - 如何使用 google-services.json 和 Google Maps API key ?

Android 谷歌地图 v2. getMapAsync() 不在单独的线程中运行?

ios - PanoramaGL如何停止旋转

image - 使用 -t 设置图像持续时间

html - Facebook - 更改缩略图

ruby-on-rails - Rails、gmaps4rails 不适用于 https

javascript - 使用 css/javascript 拉伸(stretch)背景图像

javascript - 使用Jquery或javascript如何按顺序显示图像

javascript - 创建用于处理文件的自定义 grunt 任务

javascript - 将 s3 对象数据放入数组 - Node