gpt4 book ai didi

actionscript-3 - Flash 中的地理定位

转载 作者:行者123 更新时间:2023-12-04 06:50:23 26 4
gpt4 key购买 nike

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

最佳答案

最简单的方法是使用 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>

然后,在您的应用程序中,一旦您的 map 准备就绪,将其放入一个函数中:

     //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)函数来捕获回调。

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

}

关于actionscript-3 - Flash 中的地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8945871/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com