CREATE OR REPLACE FUNCTION ITS_KK.GPSDistance(lon1 in FLOAT, lat1 in FLOAT, lon2 in FLOAT,
lat2 in FLOAT) RETURN FLOAT
AS v_addr FLOAT;
a1 FLOAT;
b FLOAT;
f FLOAT;
rlat1 FLOAT;
rlat2 FLOAT;
L FLOAT;
U1 FLOAT;
U2 FLOAT;
sinU1 FLOAT;
cosU1 FLOAT;
sinU2 FLOAT;
cosU2 FLOAT;
lambda FLOAT;
lambdap FLOAT;
iterLimit INT;
sinLambda FLOAT;
cosLambda FLOAT;
sinSigma FLOAT;
cosSigma FLOAT;
Sigma FLOAT;
sinAlpha FLOAT;
cosSqAlpha FLOAT;
cos2SigmaM FLOAT;
c FLOAT;
uSq FLOAT;
aA FLOAT;
bB FLOAT;
deltaSigma FLOAT;
s FLOAT;
begin
a1 := 6378137.0;
b := 6356752.3142;
f := 1 / 298.257223563;
rlat1 := Rad(lat1);
rlat2 := Rad(lat2);
L := Rad(lon2-lon1);
U1 := atan((1-f)*tan(rlat1));
U2 := atan((1-f)*tan(rlat2));
sinU1 := sin(U1);
cosU1 := cos(U1);
sinU2 := sin(U2);
cosU2 := cos(U2);
lambda := L;
lambdap := 0.0;
iterLimit := 100;
while(abs(lambda - lambdap)>0.000000000001 and iterLimit > 0) LOOP
sinLambda := sin(lambda) ;
cosLambda := cos(lambda) ;
sinSigma := sqrt(power((cosU2 * sinLambda), 2)+power((cosU1 * sinU2 - sinU1 * cosU2 * cosLambda), 2));
if(sinSigma=0.0)
then return 0.0;
else
cosSigma := sinU1 * sinU2 + cosU1 * cosU2 * cosLambda;
Sigma := atan2(sinSigma, cosSigma);
sinAlpha := cosU1 * cosU2 * sinLambda / sinSigma ;
cosSqAlpha := 1.0 - power(sinAlpha, 2);
cos2SigmaM := cosSigma - 2 * sinU1 * sinU2 / cosSqAlpha ;
select nvl(cos2SigmaM,0) into cos2SigmaM from dual;
C := f / 16.0 * cosSqAlpha * (4.0 + f * (4.0 - 3.0 * cosSqAlpha)) ;
lambdap := lambda;
lambda := L + (1 - C) * f * sinAlpha * (Sigma + C * sinSigma * (cos2SigmaM +
C * cosSigma * (-1 + 2.0 * power(cos2SigmaM , 2)))) ;
iterLimit := iterLimit - 1 ;
end if;
end LOOP;
if(iterLimit = 0)
then return 111;
else
uSq := cosSqAlpha*(power(a1,2)-power(b,2))/(power(b,2));
aA := 1 + uSq / 16384.0 * (4096.0 + uSq *
(-768.0 + uSq * (320.0 - 175.0 * uSq)));
bB := uSq / 1024.0 * (256.0 + uSq * (-128.0 + uSq * (74.0 - 47.0 * uSq))) ;
deltaSigma := bB * sinSigma * (cos2SigmaM + bB / 4.0 * (cosSigma
* (-1 + 2 * power(cos2SigmaM,2)) -bB / 6.0 * cos2SigmaM
* (-3 + 4 * power(sinSigma , 2)) * (-3 + 4 * power(cos2SigmaM , 2))));
s := b * aA * (Sigma - deltaSigma) ;
return s;
end if;
END GPSDistance;
/
CREATE OR REPLACE FUNCTION ITS_KK.RAD(lon in NUMBER) RETURN NUMBER
AS v_addr NUMBER;
begin
select acos(-1)*lon/180.0 into v_addr from dual ;
return v_addr;
END RAD;
/
一:创建 HelloNative.java文件
vim HelloNative.java
class HelloNative {
public native static void greeting();
static {
System.loadLibrary("HelloNative");
}
}
二:编译 HelloNative.java 生成 HelloNative.class文件。
javac HelloNative.java
ls查看编译结果:
HelloNative.class HelloNative.java
三:利用javah产生一个C的头文件。javah可执行文件可以在jdk/bin目录下查找到。
javah HelloNative
ls查看结果:
HelloNative.class HelloNative.h HelloNative.java
四:编写HelloNative.c文件
vim HelloNative.c
#include "HelloNative.h"
#include <stdio.h>
JNIEXPORT void JNICALL Java_HelloNative_greeting(JNIEnv* env, jclass cl)
{
printf("Hello Native World!\n");
}
五:生成libHelloNative.so文件
gcc -fPIC -I /usr/lib/jvm/default-java/include -I /usr/lib/jvm/default-java/include/linux -shared -o libHelloNative.so HelloNative.c
ls查看结果:
HelloNative.c HelloNative.class HelloNative.h HelloNative.java libHelloNative.so
六:在HelloNative.java中加载libHelloNative.so库,如:
static {
System.loadLibrary("HelloNative");
}
七:编写测试代码HelloNativeTest.java
vim HelloNativeTest.java
class HelloNativeTest {
public static void main(String[] args) {
HelloNative.greeting();
return;
}
}
八:编译HelloNativeTest.java文件
javac HelloNativeTest.java
ls查看结果:
HelloNative.c HelloNative.class HelloNative.h HelloNative.java HelloNativeTest.class HelloNativeTest.java libHelloNative.so
当执行java HelloNativeTest 时,会报如下错误:
Exception in thread "main" java.lang.UnsatisfiedLinkError: no HelloNative in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1681)
at java.lang.Runtime.loadLibrary0(Runtime.java:840)
at java.lang.System.loadLibrary(System.java:1047)
at HelloNative.<clinit>(HelloNative.java:4)
at HelloNativeTest.main(HelloNativeTest.java:3)
这时需要执行第九步。
九:把当前目录添加到库路径中:
java -Djava.library.path=. HelloNativeTest
或者 export LD_LIBRARY_PATH=.:$LD_LIBRARY_PATH
十:终端输出最终结果:
Hello Native World!
用来追踪触摸事件(flinging事件和其他手势事件)的速率。用obtain()函数 来获得类的实例,用addMovement(MotionEvent)函数将motion event加入到VelocityTracker类实例中,当你使用到速率时,使用computeCurrentVelocity(int)初始化速率的 单位,并获得当前的事件的速率,然后使用getXVelocity() 或getXVelocity()获得横向和竖向的速率。
VelocityTracker.computeCurrentVelocity(int units, float maxVelocity)
计算那些已经发生触摸事件点的当前速率。这个函数只有在你需要得到速率消息的情况下才调用,因为使用它需要消耗很大的性能。通过getXVelocity()和getYVelocity()获得横向和竖向的速率。
参数:
units: 你使用的速率单位.1的意思是,以一毫秒运动了多少个像素的速率, 1000表示 一秒时间内运动了多少个像素。
maxVelocity: 这个方法能计算出事件的最大速率。他的值和上面的units的值具有一样的单位,这个值必须是正数。
private VelocityTracker mVelocityTracker;//生命变量
//在onTouchEvent(MotionEvent ev)中
if (mVelocityTracker == null) {
mVelocityTracker = VelocityTracker.obtain();//获得VelocityTracker类实例
}
mVelocityTracker.addMovement(ev);//将事件加入到VelocityTracker类实例中
//判断当ev事件是MotionEvent.ACTION_UP时:计算速率
final VelocityTracker velocityTracker = mVelocityTracker;
// 1000 provides pixels per second
velocityTracker.computeCurrentVelocity(1, (float)0.01); //设置maxVelocity值为0.1时,速率大于0.01时,显示的速率都是0.01,速率小于0.01时,显示正常
Log.i("test","velocityTraker"+velocityTracker.getXVelocity());
velocityTracker.computeCurrentVelocity(1000); //设置units的值为1000,意思为一秒时间内运动了多少个像素
Log.i("test","velocityTraker"+velocityTracker.getXVelocity());