Google maps 使用fromLatLngToPoint()将V2转换为V3时,值不会出现
我正在将代码Google maps 使用fromLatLngToPoint()将V2转换为V3时,值不会出现,google-maps,google-maps-api-3,google-maps-api-2,Google Maps,Google Maps Api 3,Google Maps Api 2,我正在将代码V2转换为V3,下面的代码是googlemapV2code。在警报sw.x中出现了一些值 //Google map V2 code: function flagIntersectingMarkers() { var pad = this.borderPadding; var zoom = this.map.getZoom(); var projection = this.map.getCurrentMapType().getProjection();
V2
转换为V3
,下面的代码是googlemap
V2
code。在警报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,并且没有检查方法的参数列表。确保
您好,任何人都可以为V2到V3的迁移提供帮助。我正在提醒投影值,它显示为object。如何打印对象?请帮忙。!!!如果您在jsfiddle上发布了一个完整的v2代码工作示例,以及map,If将非常有用。
//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
}