【发布时间】:2016-05-26 12:21:53
【问题描述】:
我有一些代码可以检测位置并返回经度和纬度。它将这些值存储在一个变量中,然后将它们添加到一个 URL,然后用于打开一个 webview。我遇到的问题是应用程序需要几毫秒才能获得位置日期,然后当应用程序加载 web 视图时,坐标显示为“未定义”,因为尚未收到位置数据。如果我创建一个警报并使用坐标回显 URL,然后设置超时(1 毫秒有效),那么警报将打印正确的信息。
我尝试在创建 web 视图的按钮上设置超时,但这似乎不起作用。
我可以采取其他方法吗?谢谢
var coords;
Titanium.Geolocation.getCurrentPosition(function(e) {
if (e.error) {
alert('Error: ' + e.error);
} else {
coords = e.coords.latitude;
}
});
setTimeout(function() {
alert("http://mywebsite.com/api/return-latlong/"+coords);
}, 500);
// Keep track of selected button and our button views
var buttonIdx = 0,
buttons=[];
// Definition of buttons to generate
var buttonsToCreate = [
{icon: '/images/icon1.png', icon2: '/images/icon1.png', name: "Webview1", url: "http://http://mywebsite.com/test.php?"+coords},
{icon: '/images/icon1.png', icon2: '/images/icon1.png', name: "Webview2", url: "http://mywebsite.com/page1"},
{icon: '/images/icon1.png', icon2: '/images/icon1.png', name: "Webview3", url: "http://mywebsite.com/page2"},
];
// Open Window
$.index.open();
【问题讨论】:
标签: javascript ios titanium appcelerator