1

我正在将代码转换V2V3,以下代码是google map V2代码。在警报中,sw.x一些价值即将到来。

//Google map V2 code:
function flagIntersectingMarkers()  {
   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);
   alert("sw"+sw.x); // In this alert some value is coming
   sw = new GPoint(sw.x-pad, sw.y+pad);
  sw = projection.fromPixelToLatLng(sw, zoom, true);
 }

//Google map V3 code:
function flagIntersectingMarkers()  {
   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);
   alert("sw"+sw.x); // Undefined value is coming
   sw = new google.maps.Point(sw.x-pad, sw.y+pad);
   sw = projection.fromPointToLatLng(sw, zoom, true);
 }

但是在上面的V3代码中,在alert undefined value sw.xis来的时候,如何取回.sw.xV3

4

1 回答 1

2

您面临的问题是您没有正确地将一些调用从 v2 转换为 v3,并且没有检查方法的参数列表。确保您使用的是最新的 API 文档

//Google map V3 code:
function flagIntersectingMarkers()  {
   var pad = this.borderPadding;
   var zoom = this.map.getZoom();              // Returns number
   var projection = this.map.getProjection();  // Returns Projection
   var bounds   = this.map.getBounds();        // Returns LatLngBounds
   var sw = bounds.getSouthWest();             // Returns LatLng
   var swpt = projection.fromLatLngToPoint(sw); // WRONG in original code 2nd argument is Point, and not needed, plus should not overwrite sw
   alert("swpt"+swpt.x); // Should be defined now
   swptnew = new google.maps.Point(swpt.x-pad, swpt.y+pad); // Build new Point with modded x and y
   swnew = projection.fromPointToLatLng(swptnew, true);  //Build new LatLng with new Point, no second argument, true for nowrap
}
于 2013-06-21T19:26:46.437 回答