I am programming a page with a Map where I need to fix the Tap / Click location on the map and save the coordinates. I am using OpenLayers js. On desktop browsers (IE / FF / Chrome) this works fine. On mobile devices, the tap is correctly fixed in the default Android browser (both in real devices and in emulators).
However, in mobile web browser browsers (iPhone Safari and Android Chrome Beta), we have a problem when the taps are captured a few pixels higher (north) from the actual tap. The error is not fixed (so I canβt just add 100 to the xy event to recalibrate the top.)
Here is the code that I use as a click handler:
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;
Should I do something different? Has anyone else seen an inaccuracy issue in mobile web kit browsers when using OpenLayers?
source share