【问题标题】:Google Map now showing Marker is I add custom icon谷歌地图现在显示标记是我添加自定义图标
【发布时间】:2015-05-08 06:04:34
【问题描述】:

我的代码如下。它现在正在工作,但如果我取消注释图标行(//icon:'http://108.163.162.202:8080/finex/img/map_marker.png'),所有标记及其标题都不会显示。

我想在我的页面中添加我的自定义标记,但我的代码不允许我这样做。

请帮忙。

$(function() {
  
  var locations = [
      ['Jersey City', 40.7178746, -74.0718356],
      ['Bronx', 40.8504989, -73.84934,5 ],
      ['Union City', 40.7667435, -74.0303289],
      ['Queens', 40.651018, -73.871192],
      ['Ridgefield', 40.8256436, -74.0153092]
    ];

    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 11,
      center: new google.maps.LatLng(40.7590615, -73.969231),
      mapTypeId: google.maps.MapTypeId.ROADMAP,
	  scrollwheel: false,
	   mapTypeControl: false,
	   scaleControl: false,
	   navigationControl: true,
	   draggable: false,
	   zoomControlOptions: {
		  style: google.maps.ZoomControlStyle.LARGE 
		},
	  

    });

    var infowindow = new google.maps.InfoWindow();

    var marker, i;

    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i][1], locations[i][2]),
        map: map,
		title: locations[i][0],
        //icon: 'http://108.163.162.202:8080/finex/img/map_marker.png',
      });

      google.maps.event.addListener(marker, 'click', (function(marker, i) {
        return function() {
          infowindow.setContent(marker.title);
          infowindow.open(map, marker);
        }
      })(marker, i));
	 
	  
    }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>


<div style="height:300px;width:500px;" id="map"></div>

【问题讨论】:

标签: javascript jquery google-maps google-maps-api-3 dom-events


【解决方案1】:
I did this in my project
<input type="hidden" value="http://108.163.162.202:8080" id="baseUrl" >
var baseUrl=$('#baseUrl').val(); 
 icon: new google.maps.MarkerImage( 
                    baseUrl+'images/marker-new.png',
                    null,
                    null,
                    // new google.maps.Point(0,0),
                    null,
                    new google.maps.Size(36, 36)
                ),

【讨论】:

    【解决方案2】:

    使用 .htaccess 对图像进行有限访问。我必须输入用户名和密码。也许这就是问题所在? ;) 此外,如果后面没有任何内容,您可以在 icon 语句后留下逗号。

    【讨论】:

      猜你喜欢
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      • 2018-01-13
      • 2013-08-21
      相关资源
      最近更新 更多