這有點寬泛,但我們現在去了:我的三角測量算法出現了一個非常奇怪的問題。有時候,它會返回正確的經度/緯度,然後經過一段時間後,它會返回錯誤的緯度/經度。更奇怪的是,我無法預測什麼時候會發生這個錯誤,也不能重現它。即使我不更改我的代碼中的行(即接收正確的值,然後錯誤,然後正確,等等),它也會發生。在Android中使用三角測量收到的錯誤位置
我正在使用谷歌GLM服務,發送設備LAC(位置區號)和塔ID到三角形我的位置。我的算法的核心方法是如下:
private double[] getPositionByTriangle(int lac, int cid) {
int shortcid = cid & 0xffff;
double location[] = new double[2];
try {
String surl = "http://www.google.com/glm/mmap";
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(surl);
httppost.setEntity(new CellIDRequestEntity(shortcid, lac));
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
DataInputStream dis = new DataInputStream(entity.getContent());
// Read some prior data
dis.readShort();
dis.readByte();
// Read the error-code
int errorCode = dis.readInt();
if (errorCode == 0) {
location[0] = (double) dis.readInt()/1000000D;
location[1] = (double) dis.readInt()/1000000D;
}
} catch (Exception e) {}
return location;
}
額外的信息,也許可以提供一些幫助:此方法是在擴展Android的服務類,調用到1分鐘的延遲使用的PendingIntent。調用它的線程保存SharedPreferences中的緯度/經度值,然後在我所有的視圖中使用它。
我想知道如果我已經實施了錯誤算法的方法,或者如果我錯過了一個過程中的技巧。目前,我的正確aproximated經/緯度值緯度= -23和經度= -46,但我收到(有時)緯度= 17和經度= 81的值。有人能給我提示發生了什麼嗎?