在GPS固定范围内搜寻坐标点
请问这页的程序代码中间有个distance变量,小弟程序功力颇差,那个distance似乎是把离自己位置最近的五个点依序比对后印出标记在地图上,可是我想设定在一个固定范围内搜寻到某几个点并印出在地图上,例如300尺内搜寻在300尺内的坐标点。请问各位先进怎么改比较好?
package range.com;
import java.util.ArrayList;
import android.util.Log;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
public class searchNearestStation{
int numberOfNearestStations = 1;//設定搜尋四個門市 跟mian.java有甚麼不同? ??不管我這設多少,好像都沒甚麼改變
stationData stationData1;
private ArrayList<rawData> NearestStations = new ArrayList<rawData>();
private double tempDistances[];
public void setNumberOfNearestStationss(int numberOfNearestStations){
this.numberOfNearestStations = numberOfNearestStations;
}
public void initSearch(){
stationData1 = new stationData();
stationData1.putData();
tempDistances = new double[numberOfNearestStations];
}
public void startToFind(GeoPoint center){
for(double a :tempDistances){
Log.e("ffff", ""+a);
}
for(int i = 0 ; i < stationData1.getTotalNumber() ; i ++ )
{
rawData tempRawData = stationData1.getData(i);
// distanceBetween(center.getLatitudeE6(),center.getLongitudeE6(),tempRawData.getLat(),tempRawData.getLng());
//卓勳說要算出兩點距離這個不要用
double distance = Math.abs(center.getLatitudeE6()/1E6 - tempRawData.getLat())
+ Math.abs(center.getLongitudeE6()/1E6 - tempRawData.getLng());
// double distance =100; //不管distance怎麼改都依樣是四顆星
// public double getDistance(double lat1, double lon1, double lat2, double lon2) {
// float[] results=new float[1];
// Location.distanceBetween(lat1, lon1, lat2, lon2, results);
// return results[0];
// }
// distance =1*(97/10000000);
// if(distance/0.00001 <=1000){
if(i < numberOfNearestStations ){//Write into the NearestStations array directly.
NearestStations.add(tempRawData);
tempDistances[i] = distance;
}
else{
int largestIndex = getLargestIndex();
if(distance < tempDistances[largestIndex]){//寫入資料
Log.e(""+tempDistances[largestIndex],""+distance);
NearestStations.remove(largestIndex);//移除原本的地點
NearestStations.add(largestIndex, tempRawData);
tempDistances[largestIndex] = distance;
}
}
// }
} //end for
}
public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)
{
Log.e("results", ""+results);
}
private void distanceBetween(int latitudeE6, int longitudeE6,
double lat, double lng) {
// TODO Auto-generated method stub
}
private int getLargestIndex(){
double tempDist = 0;
int largestIndex = 0;
for(int j = 0 ; j < numberOfNearestStations ; j ++ ){
if(tempDist <= tempDistances[j]){
//To keep the value and index.
tempDist = tempDistances[j];
largestIndex = j;
}
}
return largestIndex;
}
public ArrayList getNearestStations(){
return NearestStations;
}
}
补充:移动开发 , Android