我正在将代码V2
转换为V3
,以下代码为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
代码中,在警告sw.x
未定义的值即将到来时,如何检索sw.x
中的V3
值。
答案 0 :(得分: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
}