Marker off-set on Google Map API v3

后端 未结 4 1999
忘掉有多难
忘掉有多难 2021-01-01 20:54

I\'ve created a simple map with custom PNG markers. Is it possible to offset the attached PNG image? There does not seem to be any mention of an \'offset\' in the Google Ma

4条回答
  •  醉话见心
    2021-01-01 21:24

    As of v3.10, the MarkerImage class has been deprecated, the Icon anonymous object should be used instead. From the documentation

    Until version 3.10 of the Google Maps JavaScript API, complex icons were defined as MarkerImage objects. The Icon object literal was added in version 3.10, and replaces MarkerImage from version 3.11 onwards.

    For example:

    var marker = new google.maps.Marker({
      map:map,
      position: map.getCenter(),
      icon: {
        url: place.icon,
        size: new google.maps.Size(71, 71),
        origin: new google.maps.Point(0, 0),
        anchor: new google.maps.Point(17, 34),
        scaledSize: new google.maps.Size(25, 25)
      }
    });
    

    example fiddle

    code snippet"

    function initialize() {
      var mapCanvas = document.getElementById('map');
      var mapOptions = {
        center: new google.maps.LatLng(44.5403, -78.5463),
        zoom: 8,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      var map = new google.maps.Map(mapCanvas, mapOptions)
      var marker = new google.maps.Marker({
        map: map,
        position: map.getCenter(),
        icon: {
          url: "http://i.stack.imgur.com/PYAIJ.png",
          size: new google.maps.Size(36, 36),
          origin: new google.maps.Point(0, 0),
          anchor: new google.maps.Point(18, 18),
          scaledSize: new google.maps.Size(25, 25)
        }
      });
    }
    google.maps.event.addDomListener(window, 'load', initialize);
    html,
    body,
    #map {
      width: 100%;
      height: 100%;
    }
    
    

提交回复
热议问题