【问题标题】:Google Maps API only one marker icon appearsGoogle Maps API 只出现一个标记图标
【发布时间】:2014-03-11 04:10:46
【问题描述】:

我正在尝试在地图上放置两个标记。但由于某种原因,只有其中一个作为红色标记图标。 在多台计算机上检查过,必须注意我正在使用 WAMP 服务器运行。

地图按原样显示,但只有“Marker2”有红色标记图标。

这是我的代码:

<!DOCTYPE html>
<html>
 <head>
<title>Customer map</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<META HTTP-EQUIV="Refresh" CONTENT="420">
<style type="text/css">
  html, body, #map-canvas {
    height: 100%;
    margin: 0px;
    padding: 0px
  }

   .labels {
 color: orange;
 background-color: black;
 font-family: "Lucida Grande", "Arial", sans-serif;
 font-size: 10px;
 font-weight: bold;
 text-align: center;
 width: 100px;     
 border: 2px solid black;
 white-space: nowrap;}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="https://jquery-xml2json-plugin.googlecode.com/svn/trunk/jquery.xml2json.js" type="text/javascript" language="javascript"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src="http://google-maps-utility-library-v3.googlecode.com/svn/tags/markerwithlabel/1.0.1/src/markerwithlabel.js"></script>
<script>
var map = null;

function geocodeAddress(lat, lon, image, custname) {

 var myLatlng = new google.maps.LatLng(lat,lon);
 var marker = new MarkerWithLabel({
   position: myLatlng,
   map: map,
   icon: image,
   labelContent: custname,
   labelAnchor: new google.maps.Point(22, 0),
   labelClass: "labels", // the CSS class for the label
   labelStyle: {opacity: 0.75}
 });

}

 function initialize() {
      var chicago = new google.maps.LatLng(0,0);
      var mapOptions = {
                     zoom: 2,
                     center: chicago,
                     mapTypeId: google.maps.MapTypeId.HYBRID
 }

   map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
   geocodeAddress (49.0240107,8.7582988,'http://maps.google.com/mapfiles/ms/micons/red-dot.png',"Marker1");
   geocodeAddress (30.267153,8.7582988,'http://maps.google.com/mapfiles/ms/micons/red-dot.png',"Marker2");
 }
   google.maps.event.addDomListener(window, 'load', initialize);


    </script>
 </head>
  <body>
    <div id="map-canvas"></div>
  </body>

【问题讨论】:

  • 既然已经有了坐标,为什么还要使用地理编码器?
  • @geocodezip:他没有使用地理编码器,这只是一个误导性的函数名
  • 是的,很抱歉忘记更改名称。

标签: javascript google-maps google-maps-api-3


【解决方案1】:

这一定是一个错误(我目前无法告诉你在哪里)。

现在我建议使用发布版本而不是实验 API 版本(两个标记都将被绘制):

https://maps.googleapis.com/maps/api/js?v=3&sensor=false

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-05-25
    • 2018-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-30
    • 1970-01-01
    相关资源
    最近更新 更多