2013-06-20 49 views
1

我將代碼V2轉換爲V3,以下代碼是google mapV2代碼。在警報sw.x一些價值即將到來。使用fromLatLngToPoint()將V2轉換爲V3時,值不是來自

//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值。

+0

你好,任何機構都可以請求幫助將V2遷移到V3。 –

回答

2

您面臨的問題是您沒有正確地將一些呼叫從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 
} 
+0

我提醒投影值,它顯示爲對象。如何打印對象?請幫忙。!!! –

+0

如果你真的可以幫助你發佈你的v2代碼的完整工作示例,在jsfiddle上使用map。 –

+0

console.log(obj) – magicspon

相關問題