【问题标题】:While converting the V2 to V3 using fromLatLngToPoint(), value is not coming使用 fromLatLngToPoint() 将 V2 转换为 V3 时,价值未到来
【发布时间】:2013-06-20 13:48:18
【问题描述】:

我正在将代码V2转换为V3,下面的代码是google mapV2代码。在警报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代码中,在sw.x未定义值即将到来的警报中,如何检索V3中的sw.x值。

【问题讨论】:

  • 您好,任何机构都可以帮助将 V2 迁移到 V3。

标签: google-maps google-maps-api-3 google-maps-api-2


【解决方案1】:

您面临的问题是您没有正确地将一些调用从 v2 转换为 v3,并且没有检查方法的参数列表。确保you're using the latest API docs

//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
}

【讨论】:

  • 我正在提醒投影值,它显示为对象。如何打印对象?请帮忙。!!!
  • 如果您在 jsfiddle 上发布了一个完整的 v2 代码工作示例(带有地图),这真的会有所帮助。
猜你喜欢
  • 2017-06-04
  • 2021-09-22
  • 2013-12-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多