fromLatLngToPoint未定义

问题描述 投票:0回答:1

我目前正在使用谷歌地图,当我尝试在我的代码中自定义谷歌地图工具提示时,它给我一个错误fromLatLngToPoint未定义搜索并尝试了一些解决方案,但没有得到解决方案。

这是我的代码

function initialize() 
  {
    var mapOptions = {
      zoom: 14,
      styles: [
        {
          "featureType": "water",
          "stylers": [
            { "color": "#1CA5EA" }
          ]
        },{
          "featureType": "landscape.natural",
          "stylers": [
            { "color": "#EDEDED" }
          ]
        },{
          "featureType": "landscape.man_made",
          "stylers": [
            { "color": "#E0E0E0" }
          ]
        },{
          "featureType": "road.highway",
          "stylers": [
            { "visibility": "off" }
          ]
        },{
          "featureType": "poi",
          "elementType": "geometry",
          "stylers": [
            { "visibility": "on" },
            { "gamma": 0.53 },
            { "saturation": 4 },
            { "lightness": -8 }
          ]
        },{
          "featureType": "road.local",
          "elementType": "geometry.stroke",
          "stylers": [
            { "color": "#B7B7B7" }
          ]
        },{
          "featureType": "poi.school",
          "elementType": "geometry",
          "stylers": [
            { "color": "#1CA5EA" },
            { "saturation": 15 },
            { "lightness": -53 },
            { "weight": 0.1 },
            { "gamma": 0.96 }
          ]
        },{
          "featureType": "poi",
          "elementType": "geometry.fill",
          "stylers": [
            { "gamma": 0.89 },
            { "lightness": -1 },
            { "saturation": -1 },
            { "color": "#878787" }
          ]
        },{
          "featureType": "road.arterial",
          "stylers": [
            { "visibility": "simplified" }
          ]
        },{
          "featureType": "road.local",
          "stylers": [
            { "visibility": "simplified" }
          ]
        },{
        }
      ],
      center: new google.maps.LatLng(57.70610, 11.97324),
      scrollwheel: false
    };

    var map = new google.maps.Map(document.getElementById('map'), mapOptions);

    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(57.70610, 11.97324),
        map: map,

        title: 'This is us!'
    });
    marker.tooltipContent = 'this content should go inside the tooltip';
    var infoWindow = new google.maps.InfoWindow({
        content: 'This is an info window'
    });

    google.maps.event.addListener(marker, 'mouseover', function () {
        var point = fromLatLngToPoint(marker.getPosition(), map);
        $('#marker-tooltip').html(marker.tooltipContent + '<br>Pixel coordinates: ' + point.x + ', ' + point.y).css({
            'left': point.x,
                'top': point.y
        }).show();
    });
  }
google-maps google-maps-api-3 google-maps-markers
1个回答
1
投票

fromLatLngToPoint方法是Projection的方法。

var point = map.getProjection().fromLatLngToPoint(marker.getPosition());
© www.soinside.com 2019 - 2024. All rights reserved.