Flash中的地理定位技术

3

我正在使用Flash构建一个小型Web应用程序。是否有解决方案可以获取用户的地理位置?

1个回答

3
最简单的方法是与JavaScript函数进行接口。
在你的HTML中:
    <script>
        function getGEO()
        {
            // First check if your browser supports the geolocation API
            if (navigator.geolocation)
            {
                //alert("HTML 5 is getting your location");
                // Get the current position
                navigator.geolocation.getCurrentPosition(function(position)
                {
                    lat = position.coords.latitude
                    long = position.coords.longitude;
                    // Pass the coordinates to Flash
                    passGEOToSWF(lat, long);
                });
            } else {
                //alert("Sorry... your browser does not support the HTML5 GeoLocation API");
            }
        }
        function passGEOToSWF(lat,long)
        {
            //alert("HTML 5 is sending your location to Flash");
            // Pass the coordinates to mySWF using ExternalInterface
            document.getElementById("index").passGEOToSWF(lat,long);
        }
    </script>

在你的应用程序中,一旦地图准备好,将以下内容放入一个函数中:

     //for getting a user's location
            if (ExternalInterface.available) 
            {
                //check if external interface is available
                try 
                {
                    // add Callback for the passGEOToSWF Javascript function
                    ExternalInterface.addCallback("passGEOToSWF", onPassGEOToSWF);
                } 
                catch (error:SecurityError) 
                {
                    // Alert the user of a SecurityError
                } 
                catch (error:Error) 
                {
                    // Alert the user of an Error
                }
            }

最后,准备一个私有函数来捕获回调。
    private function onPassGEOToSWF(lat:*,long:*):void
    {
        userLoc = new LatLng(lat,long);
        map.setCenter(userLoc);

    }

太棒了!谢谢。您有没有想过如何从Adobe Air桌面应用程序中获取地理位置? - Uli
真他妈的,我以为会有可行的解决方案。不过还是谢谢。 - Uli
我想说的是,从未使用过Air,因此我不知道如何操作。对于措辞不当表示抱歉。 - the_skua

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接