Google maps 将google map V2转换为V3代码,以便在google map中设置标记

Google maps 将google map V2转换为V3代码,以便在google map中设置标记,google-maps,google-maps-api-3,google-maps-api-2,Google Maps,Google Maps Api 3,Google Maps Api 2,我是V3新手。我正在将V2代码转换为V3。在下面的函数中,投影值不出现。从该投影中,它们用于LatlnGTOPIxel和PixelToLatlng。而不是这两个功能,如何在V3谷歌地图使用。getLatLang还介绍了如何在V3谷歌地图中使用。请帮忙 function flagContainedMarkers (){ // Iterate through the markers and only set makeVisible to // true if the marker is insi

我是V3新手。我正在将V2代码转换为V3。在下面的函数中,投影值不出现。从该投影中,它们用于LatlnGTOPIxel和PixelToLatlng。而不是这两个功能,如何在V3谷歌地图使用。getLatLang还介绍了如何在V3谷歌地图中使用。请帮忙

  function flagContainedMarkers (){
// Iterate through the markers and only set makeVisible to
// true if the marker is inside the map bounds & padding
var pad = this.borderPadding;

var zoom        = this.map.getZoom();
var projection  = this.map.getCurrentMapType().getProjection();
var bounds      = this.map.getBounds();

var sw = bounds.getSouthWest();
sw = projection.fromLatLngToPixel(sw, zoom);
sw = new google.maps.Point(sw.x-pad, sw.y+pad);
sw = projection.fromPixelToLatLng(sw, zoom, true);

var ne = bounds.getNorthEast()
ne = projection.fromLatLngToPixel(ne, zoom);
ne = new google.maps.Point(ne.x+pad, ne.y-pad);
ne = projection.fromPixelToLatLng(ne, zoom, true);

var paddedBounds = new google.maps.LatLngBounds(sw, ne);

for (var i = this.markers.length-1; i>=0; i--) {
    var marker = this.markers[i];
    marker.makeVisible = paddedBounds.containsLatLng(marker.getLatLng()) ? true:false;
}
}

下面是代码中的一些替换项…试试这个

function flagContainedMarkers (){ // Iterate through the markers and only set makeVisible to true if the marker is inside the map bounds & padding
   var pad = this.borderPadding;
   var zoom        = this.map.getZoom();
   var projection  = this.map.getProjection();
   var bounds      = this.map.getBounds();

   var sw = bounds.getSouthWest();
       sw = projection.fromLatLngToPoint(sw, zoom);
       sw = new google.maps.Point(sw.lat()-pad, sw.lng()+pad);
       sw = projection.fromPointToLatLng(sw, zoom, true);

   var ne = bounds.getNorthEast()
       ne = projection.fromLatLngToPoint(ne, zoom);
       ne = new google.maps.Point(ne.lat()+pad, ne.lng()-pad);
       ne = projection.fromPointToLatLng(ne, zoom, true);

    var paddedBounds = new google.maps.LatLngBounds(sw, ne);
    for (var i = this.markers.length-1; i>=0; i--) {
       var marker = this.markers[i];
       marker.makeVisible = paddedBounds.contains(marker.position()) ? true:false;
    }
}

您好,任何人都可以为V2到V3的迁移提供帮助。您好,谢谢您的代码。在该代码中,sw.x值表示为“未定义”。因此,我提醒它sw.x-pad值为NaN。由于这个原因,我无法继续下一步。请帮忙!!!大家好,请回复上面的评论。我编辑了我的答案…检查一下…我忘了用sw.lat()/ne.lat()替换sw.x/ne.x,用sw.lng()/ne.lng()替换sw.y/ne.y。。。。