我无法将标记放置在已由其他符号标记的地方。 [英] I am not able to place markers on the places which is already marked by google with other symbols .

查看:97
本文介绍了我无法将标记放置在已由其他符号标记的地方。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

信息窗口和标记不显示已被google标记的地点。例如:如果您运行代码并在任何地方点击,结果会出现一个标记和一个信息窗口,但这不会发生在诸如不伦瑞克,露天剧场等标记的地方。

The info window and marker is not shown for the places which is already marked by google. for example: if you run the code and click anywhere , a marker and a info window will appear as a result , but this doesn't happen for the places which are alreasy marked such as "The Brunswick","Open Air Theatre" etc.

<!DOCTYPE html>
<html>
<head>
<script
src="http://maps.googleapis.com/maps/api/js">
</script>

<script>
var map;
var myCenter=new google.maps.LatLng(51.508742,-0.120850);

function initialize(){
    var mapProp = {
        center:myCenter,
        zoom:14,
        mapTypeId:google.maps.MapTypeId.ROADMAP
    };

    map = new google.maps.Map(document.getElementById("googleMap"),mapProp);

    google.maps.event.addListener(map, 'click', function(event) {
        placeMarker(event.latLng);
    });
}

function placeMarker(location) {
    var marker = new google.maps.Marker({
        position: location,
        map: map,
    });
    var infowindow = new google.maps.InfoWindow({
        content: 'Latitude: ' + location.lat() + ' Longitude: ' + location.lng() 
    });
    infowindow.open(map,marker);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>

<body>
    <div id="googleMap" style="width:1000px;height:1000px;"></div>
</body>
</html>


推荐答案

当你点击这样一个地方将不会在地图上触发点击。

When you click on such a place(POI) there will no click be triggered on the map.

当您不想隐藏POI时,您必须触发您自己的点击。

When you don't want to hide the POI's, you must trigger the click on your own.

可能的方法(请参阅:当用户点击地图上的(商业)地点时,如何获得点击事件

Possible approach(see: How to get a click event when a user clicks a (business) place on the map )

//keep a reference to the original setPosition-function
var fx = google.maps.InfoWindow.prototype.setPosition;

//override the built-in setPosition-method
google.maps.InfoWindow.prototype.setPosition = function () {

  //this property isn't documented, but as it seems
  //it's only defined for InfoWindows opened on POI's
  if (this.logAsInternal) {
    google.maps.event.addListenerOnce(this, 'map_changed',function () {
      var map = this.getMap();
      //the infoWindow will be opened, usually after a click on a POI
      if (map) {
        //trigger the click
        google.maps.event.trigger(map, 'click', {latLng: this.getPosition()});
        //hide the default-infoWindow of the POI
        this.setMap(null);
      }
    });
  }
    //call the original setPosition-method
  fx.apply(this, arguments);
};

演示: http://jsfiddle.net/doktormolle/1yrpm98q/

这篇关于我无法将标记放置在已由其他符号标记的地方。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆