2013-03-07 39 views
0

我需要幫助做這個查詢與JDO:查詢半正矢與JDO

SELECT id, (3959 * acos(cos(radians(lat_t)) * cos(radians(lat)) * cos(radians(lng) - radians(lng_t)) 
    + sin(radians(lat_t)) * sin(radians(lat)))) AS distance 
FROM Stores HAVING distance < 25 
ORDER BY distance 

我想諮詢與接近座標,和許多互聯網搜索,我發現這個算法半正弦波。 The source is Google

這是你所需要的:

public static ArrayList<User> getUsers(double lat, double lng, double distance) { 
    PersistenceManager pm = PMF.get().getPersistenceManager(); 
    Query query = pm.newQuery(¿?¿?¿?); 

    ... 

    return users; 
} 

謝謝!

回答

0

來源:http://db.apache.org/jdo/jdoql_methods.html

When writing the "filter" for a JDOQL Query you can make use of some methods on the various Java 
types. The range of methods included as standard in JDOQL is not as flexible as with the true Java 
types, but the ones that are available are typically of much use. 

您應該查找自己的價值觀並應用這些值想用的任何方法。

對於排序的一部分,Query接口有一個稱爲setOrdering方法,傳遞給它yourColumn ASC|DESC(即ASC OR DESC