您好,登錄后才能下訂單哦!
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title></title>
<link rel="stylesheet" href="sdk-touch/resources/css/sencha-touch.css" />
<link rel="stylesheet" href="resources/css/app.css" />
<!--<script src="sdk-touch/sencha-touch.js"></script>-->
<script src="sdk-touch/sencha-touch-all.js"></script>
<!--<script src="sdk-touch/sencha-touch-all-debug.js"></script>-->
<!--<script src="sdk-touch/sencha-touch-debug.js"></script>-->
<script src="app.js"></script>
</head>
<body>
</body>
</html>
/**
* Created by-PC on 2014/8/12.
*/
Ext.define('MyApp.controller.calculate', {
toRad: function (d) {
return d * Math.PI / 180;
},
getDisance: function (lat1, lng1, lat2, lng2) { //#lat為緯度, lng為經(jīng)度, 一定不要弄錯(cuò)
var dis = 0;
var radLat1 = this.toRad(lat1);
var radLat2 = this.toRad(lat2);
var deltaLat = radLat1 - radLat2;
var deltaLng = this.toRad(lng1) - this.toRad(lng2);
var dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));
return dis * 6378137;
}
});
/**
* Created by-PC on 2014/8/12.
*/
Ext.define('MyApp.controller.controller', {
extend: 'Ext.app.Controller',
launch: function () {
this.callParent(arguments);
console.log('launch');
//北京天安門的地理坐標(biāo)
var pk_la = 39.90960456049752;
var pk_lo = 116.3972282409668;
/*Ext.util.geolocation.getCurrentPosition(function (position) {
console.log(position.coords.latitude);
console.log(position.coords.longitude);
});*/
//var me_la = Ext.device.geolocation.latitude;
//var me_lo = Ext.device.geolocation.longitude;
navigator.geolocation.getCurrentPosition(function(position){
//alert(position.coords.latitude+'+'+position.coords.longitude);
//var me_la = Ext.Device.Geolocation.getLatitude;//不能實(shí)現(xiàn)獲取
//var me_lo = Ext.Device.Geolocation.getLongitude;//不能實(shí)現(xiàn)獲取
var me_la = position.coords.latitude;
var me_lo = position.coords.longitude;
var g = Ext.create('MyApp.controller.calculate');
var distance = g.getDisance(pk_la, pk_lo, me_la, me_lo);
//console.log(me_la);
//console.log(me_lo);
//console.log(distance);
Ext.getCmp('locLabelID').setValue(distance+'米');
});
},
init: function () {
this.callParent();
console.log('init1');
}
});
/**
* Created by-PC on 2014/8/12.
*/
Ext.define('MyApp.view.mainContainer',{
extend:'Ext.Container',
alias: 'widget.mainContainer',
requires: ['Ext.Toolbar'],
initialize:function(){
this.callParent();
var topToolBar={
xtype:'toolbar',
title:'直線距離',
docked:'top',
items:[
{
xtype:'spacer'
}
]
};
var locLabel = {
xtype: 'textfield',
name: 'title',
label: '你與天安門的距離是:',
id:'locLabelID'
};
this.add([
topToolBar,
locLabel
]);
}
/*config:{
layout: {
type: 'fit'
}
}*/
});
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。