Geolocation in Flash

后端 未结 1 621
日久生厌
日久生厌 2021-01-20 01:46

I\'m building a small web app in Flash. Is there a solution to get the geo-location of a user?

1条回答
  •  旧时难觅i
    2021-01-20 02:33

    The easiest way is to interface with a JavaScript function.

    In your HTML:

        
    

    Then, in your Application, once your map is ready, put this in a function:

         //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
                    }
                }
    

    Finally, have a private function ready to catch the callback.

        private function onPassGEOToSWF(lat:*,long:*):void
        {
            userLoc = new LatLng(lat,long);
            map.setCenter(userLoc);
    
        }
    

    0 讨论(0)
提交回复
热议问题