ExtJS经典工具包的Geolocation用法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ExtJS经典工具包的Geolocation用法相关的知识,希望对你有一定的参考价值。

我正在使用Sencha Touch tutorial的Geolocation用法,但我需要使用classicmodern工具包。在sencha app watch / refresh / build命令期间,我得到Ext.util.Geolocation类的要求的错误;

C2008: Requirement had no matching files (Ext.util.Geolocation)
[ERR] BUILD FAILED
[ERR] com.sencha.exceptions.ExBuild: Failed to find any files for /..../WeatherView.js::ClassRequire::Ext.util.Geolocation
[ERR]   at sun.reflect.Delegat
[ERR] ingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

尽管当我尝试sencha app watch modern命令时,我得到了Ext.form.field.Text的错误。我无法在我的应用中禁用textfield用法。那么Geolocation服务的解决方案是什么?

这是一个出现错误的代码片段:

refreshGeoLocation : function( refresh ) {
    if (!this.geoLocationObj || (true == refresh)) {
        Ext.create('Ext.util.Geolocation', {
            autoUpdate: false,
            listeners: {
                locationupdate: function (geo) {
                    Ext.Msg.alert('Refresh Geolocation', 'New latitude: ' + geo.getLatitude() + ' , Longitude: ' + geo.getLongitude(), Ext.emptyFn);
                },
                locationerror: function (geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) {
                    if (bTimeout) {
                        alert('Timeout occurred');
                    } else {
                        alert('Error occurred');
                    }
                }
            }
        });

        this.geoLocationObj.updateLocation();
    }
}

(*)教程:https://wtcindia.wordpress.com/2013/02/08/using-yahoo-weather-api-in-sencha-touch/

答案

这个错误的原因(Requirement had no matching files (Ext.util.Geolocation))可能是某个地方(app.js or Application.js)你需要这个类Ext.util.Geolocation

Ext.util.Geolocation仅适用于modern工具包。因此,你应该在app.js文件夹中找到modern而不是Ext.form.field.Text

对于这个“尽管当我尝试使用sencha app观看现代命令时,我得到Ext.form.field.Text的错误。”

这个类Ext.form.field.Text只提供经典工具包。而不是这个Ext.field.Text你需要在modern工具包中使用这个Geolocation

如果你想在classic工具包中使用classic,那么你需要在ExtJS-GeoLocation文件夹中添加自定义类。

有关详细信息,请参阅我的/** * Provides a cross browser class for retrieving location information. * Source from https://docs.sencha.com/extjs/6.0.0/modern/src/Geolocation.js.html * Based on the [Geolocation API Specification](http://dev.w3.org/geo/api/spec-source.html) * * When instantiated, by default this class immediately begins tracking location information, * firing a {@link #locationupdate} event when new location information is available. To disable this * location tracking (which may be battery intensive on mobile devices), set {@link #autoUpdate} to `false`. * * When this is done, only calls to {@link #updateLocation} will trigger a location retrieval. * * A {@link #locationerror} event is raised when an error occurs retrieving the location, either due to a user * denying the application access to it, or the browser not supporting it. * * The below code shows a GeoLocation making a single retrieval of location information. * * //{GeoLocation} is your application name * var geo = Ext.create('GeoLocation.util.Geolocation', { * autoUpdate: false, * listeners: { * locationupdate: function(geo) { * Ext.Msg.alert('Success', `New latitude: ${geo.getLatitude()} <br>New Longitude: ${geo.getLongitude()}`); * }, * locationerror: function(geo, bTimeout, bPermissionDenied, bLocationUnavailable, message) { * if(bTimeout){ * Ext.Msg.alert('Error', 'Timeout occurred.'); * } else { * Ext.Msg.alert('Error', 'Error occurred'); * } * } * } * }); * geo.updateLocation(); */ //{GeoLocation} is your application name Ext.define('GeoLocation.util.Geolocation', { extend: 'Ext.Evented', alternateClassName: ['Geolocation'], config: { /** * @event locationerror * Raised when a location retrieval operation failed. * * In the case of calling updateLocation, this event will be raised only once. * * If {@link #autoUpdate} is set to `true`, this event could be raised repeatedly. * The first error is relative to the moment {@link #autoUpdate} was set to `true` * (or this {@link Ext.util.Geolocation} was initialized with the {@link #autoUpdate} config option set to `true`). * Subsequent errors are relative to the moment when the device determines that it's position has changed. * @param {Ext.util.Geolocation} this * @param {Boolean} timeout * Boolean indicating a timeout occurred * @param {Boolean} permissionDenied * Boolean indicating the user denied the location request * @param {Boolean} locationUnavailable * Boolean indicating that the location of the device could not be determined. * For instance, one or more of the location providers used in the location acquisition * process reported an internal error that caused the process to fail entirely. * @param {String} message An error message describing the details of the error encountered. * * This attribute is primarily intended for debugging and should not be used * directly in an application user interface. */ /** * @event locationupdate * Raised when a location retrieval operation has been completed successfully. * @param {Ext.util.Geolocation} this * Retrieve the current location information from the GeoLocation object by using the read-only * properties: {@link #latitude}, {@link #longitude}, {@link #accuracy}, {@link #altitude}, {@link #altitudeAccuracy}, {@link #heading}, and {@link #speed}. */ /** * @cfg {Boolean} autoUpdate * When set to `true`, continually monitor the location of the device (beginning immediately) * and fire {@link #locationupdate} and {@link #locationerror} events. */ autoUpdate: true, /** * @cfg {Number} frequency * The frequency of each update if {@link #autoUpdate} is set to `true`. */ frequency: 10000, /** * @cfg {Number} latitude * Read-only property representing the last retrieved * geographical coordinate specified in degrees. * @readonly */ latitude: null, /** * @cfg {Number} longitude * Read-only property representing the last retrieved * geographical coordinate specified in degrees. * @readonly */ longitude: null, /** * @cfg {Number} accuracy * Read-only property representing the last retrieved * accuracy level of the latitude and longitude coordinates, * specified in meters. * * This will always be a non-negative number. * * This corresponds to a 95% confidence level. * @readonly */ accuracy: null, /** * @cfg {Number} altitude * Read-only property representing the last retrieved * height of the position, specified in meters above the ellipsoid * [WGS84](http://dev.w3.org/geo/api/spec-source.html#ref-wgs). * @readonly */ altitude: null, /** * @cfg {Number} altitudeAccuracy * Read-only property representing the last retrieved * accuracy level of the altitude coordinate, specified in meters. * * If altitude is not null then this will be a non-negative number. * Otherwise this returns `null`. * * This corresponds to a 95% confidence level. * @readonly */ altitudeAccuracy: null, /** * @cfg {Number} heading * Read-only property representing the last retrieved * direction of travel of the hosting device, * specified in non-negative degrees between 0 and 359, * counting clockwise relative to the true north. * * If speed is 0 (device is stationary), then this returns `NaN`. * @readonly */ heading: null, /** * @cfg {Number} speed * Read-only property representing the last retrieved * current ground speed of the device, specified in meters per second. * * If this feature is unsupported by the device, this returns `null`. * * If the device is stationary, this returns 0, * otherwise it returns a non-negative number. * @readonly */ speed: null, /** * @cfg {Date} timestamp * Read-only property representing when the last retrieved * positioning information was acquired by the

以上是关于ExtJS经典工具包的Geolocation用法的主要内容,如果未能解决你的问题,请参考以下文章

Extjs 6 - 现代工具包 ui-mixins 构建错误

如何从 EXTJS 中的委托事件中获取记录?

Extjs 经典网格面板滚动

如何从ExtJs网格中删除列?

在extjs经典网格中开始编辑单元格

[网络安全提高篇] 一一七.恶意软件静态分析经典工具Capa基本用法万字详解