如何在titatnium中显示警报的当前位置点(钛中的地理位置).我没有找到任何好的教程.你能举个例子吗?
我找到了一些第一,您需要定义为什么要使用地理位置.此消息将显示给用户. Ti.Geolocation.purpose ="位置将用于app X"; 这条线的用途是什么?我们可以在这里写任何东西这个行的位置将用于应用程序X.
我使用这个简单的代码,您可以使用纬度和经度变量打印警报:
if(Ti.Network.online){
Ti.Geolocation.purpose = "Receive User Location";
Titanium.Geolocation.getCurrentPosition(function(e){
if (!e.success || e.error)
{
alert('Could not find the device location');
return;
}
var longitude = e.coords.longitude;
var latitude = e.coords.latitude;
alert("latitude: " + latitude + "longitude: " + longitude);
});
}else{
alert("Internet connection is required to use localization features");
}
Run Code Online (Sandbox Code Playgroud)