2

これが可能かどうかはわかりません...別の場所からブラウジングをテストするにはどうすればよいですか?

これは、GeoPlugin を使用する Web アプリケーションをテストするためのものです。このプラグインは、ユーザーの IP に応じて、地理情報 (都市、緯度、経度...) を提供し、Web アプリケーションはこれを使用してカスタム ホームページを生成します。

別の場所から物理的に閲覧する以外に、これをテストする方法はありますか?

ありがとうございました!

4

1 に答える 1

0

navigator.geolocation オブジェクトをオーバーライドすることで、Webkit ブラウザーで場所をモックできます。Google Chrome で次の例を試してください。

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

        <script type="text/javascript" language="JavaScript">
            /* Replace navigator.geolocation with mock */

            var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
            if (typeof navigator == "undefined" || navigator === null) {
              window.navigator = {};
            }

            // Replace real geolocation with mock geolocation
            delete navigator.geolocation;
            navigator.geolocation = {
              isMock: true,
              paused: true,
              delay: 1000,
              shouldFail: false,
              failsAt: -1,
              unFailsAt: -1,
              errorMessage: "There was an error retrieving the position!",
              currentTimeout: -1,
              lastPosReturned: 0,
              overrideAccuracy: 0, // accuracy in m to return for all positions (overrides any existing accuracies defined in the waypoints)
              useOverrideAccuracy: false, // Whether to override acurracies defined in the waypoints with the above override accuracy

              _geoCall: function(method, success, error, repeat) {

                  return this.currentTimeout = window[method].call(null, __bind(function() {

                    var nextPos;

                    if(!this.paused && this.lastPosReturned < this.waypoints.length - 1){
                        nextPos = this.lastPosReturned++;
                    }else{
                        this.lastPosReturned = nextPos = 0;
                    }


                    if(!this.shouldFail && nextPos == this.failsAt) this.shouldFail = true;
                    if(this.shouldFail && nextPos == this.unFailsAt) this.shouldFail = false;

                    if(repeat) this._geoCall("setTimeout", success, error, true);

                    if (this.shouldFail && (error != null)) {
                        return error(this.errorMessage);
                    }
                    else if (success != null && (!this.paused || !repeat)) {
                        var result = this.waypoints[nextPos];
                        result.isMock = true;
                        if(this.useOverrideAccuracy) result.coords.accuracy = this.overrideAccuracy;
                        success(result);
                        return nextPos;
                    }
                  }, this), this.delay);

              },
              getCurrentPosition: function(success, error) {
                return this._geoCall("setTimeout", success, error, false);
              },
              watchPosition: function(success, error) {
                this._geoCall("setTimeout", success, error, true);
                return this.currentTimeout;
              },
              clearWatch: function(id) {
                return clearInterval(this.currentTimeout);
              },
              waypoints: []
            };
        </script>

        <script type="text/javascript" language="JavaScript">
            navigator.geolocation.waypoints = [
                {coords:{latitude:50.001, longitude:-4.001}},
                {coords:{latitude:50.001, longitude:-4.002}},
                {coords:{latitude:50.001, longitude:-4.003}},
                {coords:{latitude:50.001, longitude:-4.004}},
                {coords:{latitude:50.001, longitude:-4.005}},
                {coords:{latitude:50.001, longitude:-4.006}},
                {coords:{latitude:50.001, longitude:-4.007}},
                {coords:{latitude:50.001, longitude:-4.007}},
                {coords:{latitude:50.001, longitude:-4.009}},
                {coords:{latitude:50.001, longitude:-4.010}},
                {coords:{latitude:50.001, longitude:-4.011}},
                {coords:{latitude:50.001, longitude:-4.012}},
                {coords:{latitude:50.001, longitude:-4.013}},
                {coords:{latitude:50.001, longitude:-4.014}},
                {coords:{latitude:50.001, longitude:-4.015}},
                {coords:{latitude:50.001, longitude:-4.016}},
                {coords:{latitude:50.001, longitude:-4.017}},
                {coords:{latitude:50.001, longitude:-4.017}},
                {coords:{latitude:50.001, longitude:-4.019}},
                {coords:{latitude:50.001, longitude:-4.020}}
            ];

            function runTests(){
                navigator.geolocation.paused = false; // run geomocking
                test1();
            }

            function test1(){
                console.log("Test 1: Get current position");
                navigator.geolocation.getCurrentPosition(
                    function(position){
                        console.log("Position updated: latitude="+position.coords.latitude+", longitude="+position.coords.longitude);
                        test2();
                    },
                    function(error){
                        console.error("Error while retrieving current position. Error code: " + error.code + ",Message: " + error.message);
                    }
                );
            }

            function test2(){
            console.log("Test 2: Watch position");
                navigator.geolocation.watchPosition(
                    function(position){
                        console.log("Position updated: latitude="+position.coords.latitude+", longitude="+position.coords.longitude);
                    },
                    function(error){
                        console.error("Error while retrieving current position. Error code: " + error.code + ",Message: " + error.message);
                    }
                );
            }

            document.addEventListener('DOMContentLoaded', runTests, false);
        </script>
    </head>
    <body>

    </body>
</html>
于 2013-10-24T22:14:54.423 に答える