問題が近くの病院を見つけることである場合は、次のコードを使用できます。
private boolean isItemInRange(double radius,
double latOrigin, double lonOrigin, double latDestination,
double lonDestination) {
double resultRadius = 6371 * Math.acos(Math.cos(Math.PI
* (90 - latDestination) / 180)
* Math.cos((90 - latOrigin) * Math.PI / 180)
+ Math.sin((90 - latDestination) * Math.PI / 180)
* Math.sin((90 - latOrigin) * Math.PI / 180)
* Math.cos((lonOrigin - lonDestination) * Math.PI / 180));
if (resultRadius <= radius){
return true;
} else {
return false;
}
}
デバイスの座標と各病院の座標を渡すだけです。データがサーバー上にある場合は、デバイス座標を送信するだけで、サーバーまたはデータベースに上記の関数を実装できます。
それがあなたを助けることを願っています。