Is there a way to Fix a Google Maps Marker to the Center of its Map always?

前端 未结 7 1357
野趣味
野趣味 2020-12-01 00:21

To be more precise, what I try to accomplish is that while I Drag a Google Map there\'s a Google Maps Marker that stays fixed

7条回答
  •  渐次进展
    2020-12-01 00:58

    A different approach, that did not use a real google.maps.Marker:

    after the map has been initialized, inject a div into the map-container, give it a className(e.g. centerMarker), the further things will be done via CSS:

    .centerMarker{
      position:absolute;
      /*url of the marker*/
      background:url(http://maps.gstatic.com/mapfiles/markers2/marker.png) no-repeat;
      /*center the marker*/
      top:50%;left:50%;
    
      z-index:1;
      /*fix offset when needed*/
      margin-left:-10px;
      margin-top:-34px;
      /*size of the image*/
      height:34px;
      width:20px;
    
      cursor:pointer;
    }
    

    Demo: http://jsfiddle.net/doktormolle/jcHqt/

提交回复
热议问题