繁体   English   中英

在Webkit Mobile浏览器中捕获的OpenLayers纬度不准确

[英]OpenLayers latitude inaccurately captured in Webkit Mobile browsers

我正在编写一个带有Map的页面,我需要捕获地图上Tap / Click的位置并存储坐标。 我正在使用OpenLayers js。 在桌面浏览器(IE / FF / Chrome)上,这很好用。 在移动设备上,可以在默认的Android浏览器上(在实际设备和模拟器中)正确捕获分路器。

然而,在移动webkit浏览器(iPhone Safari和Android Chrome Beta)上,我们遇到的问题是,在实际点击的较高(朝北)几个像素处捕捉到水龙头。 错误未修复(因此,我不能只为事件的xy添加100以重新校准顶部。)

这是我用作clickhandler的代码:

OpenLayers.Control.ClickHandler = OpenLayers.Class(OpenLayers.Control, {                
    defaultHandlerOptions: {
        'single': true,
        'double': false,
        'pixelTolerance': 0,
        'stopSingle': false,
        'stopDouble': false
    },

    initialize: function(options) {
        this.handlerOptions = OpenLayers.Util.extend(
            {}, this.defaultHandlerOptions
        );
        OpenLayers.Control.prototype.initialize.apply(
            this, arguments
        ); 
        this.handler = new OpenLayers.Handler.Click(
            this, {
                'click': this.trigger
            }, this.handlerOptions
        );
    }, 

    trigger: function(e) {
        that.inputLonLat_EPSG4326 = null;

        var lonlat = that.inputMap.getLonLatFromViewPortPx(e.xy);

        that.logMessage("XY " + e.xy);
        that.logMessage("LonLoat " + lonlat);

        that.inputMarkers.clearMarkers();


    that.inputMarkers.addMarker(new OpenLayers.Marker(lonlat,that.icons["green"].clone()));

    lonlat.transform(that.inputMap.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));

    that.inputLonLat_EPSG4326 = lonlat;
    // For the moderation sections
    $('#alertLatitude').val(that.inputLonLat_EPSG4326.lat);
    $('#alertLongitude').val(that.inputLonLat_EPSG4326.lon);

    //lonLat2.transform(that.inputMap.getProjectionObject(), new OpenLayers.Projection("EPSG:4326"));
    that.logMessage("Stored lat " + that.inputLonLat_EPSG4326.lat);
    that.logMessage("Stored lon " + that.inputLonLat_EPSG4326.lon);     

    that.callFunction(that.inputMapListener, e);
    }   
});

我应该采取不同的做法吗? 在使用OpenLayers时,有没有其他人在移动webkit浏览器上看到不准确的问题?

我终于找到了这种情况发生的原因。 似乎在webkit移动浏览器上,库似乎得到(或派生)的x,y基于页面而不是基于地图所在的元素。 因此计算结束了。 似乎不能通过添加map元素的xy或某些基于DOM的数字来解决不准确性(我试过了。)

我通过在IFrame中放置Map来解决它,然后将iFrame放在map元素中。 这样,地图点击处理程序接收的x,y在iFrame内是准确的,因此lat,long也是准确的。 由于父和iFrame都来自同一个域,因此没有问题来回传递。

为了完善上下文,基于iFrame的解决方案绝对与我测试的BB 9及以上版本,Android Chrome,Android Default和iPhone Safari兼容。

检查出的解决方案- http://suat1.vocanic.net//saralee/apps/dengue_alert/并在iFrame的http://suat1.vocanic.net//saralee/apps/dengue_alert/mobileMap.php (WIP版本可能随时间变化或破裂)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM