2012-08-15 3 views
2

다소 넓 습니다만, 여기에 나와 있습니다. 삼각 측량 알고리즘에서 매우 이상한 문제가 발생했습니다. 경우에 따라 올바른 위도/경도를 반환하고 시간이 지나면 잘못된 위도/경도를 반환합니다. 더 이상한 일은이 오류가 언제 일어날 지 예측할 수없고 재현 할 수도 없다는 것입니다. 내 코드에서 행을 변경하지 않더라도 올바른 값을받은 다음 잘못된 순서로 수정하는 등의 작업을 수행합니다.Android에서 삼각 측량으로 잘못된 위치가 수신되었습니다.

저는 Google GLM 서비스를 사용하여 장치 LAC (위치 지역 번호)와 타워 ID를 내 위치를 삼각형으로 보냅니다. 이 방법은 1 분 지연을 통해 호출 안드로이드 서비스를 확장하는 클래스에 사용됩니다 어쩌면 도움이이 될 수 있다는

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; 
} 

추가 정보 : 내 알고리즘의 핵심 방법은 다음에 PendingIntent. 그것을 호출하는 스레드는 SharedPreferences의 위도/경도 값을 저장 한 다음 모든 뷰에서 사용합니다.

잘못된 알고리즘으로 메소드를 구현했는지 또는 내가 놓친 프로세스에서 트릭이 발생하는지 궁금합니다. 위도 = 17경도 = 81의 값은 현재 내 정확한 aproximated 위도/경도 값은 = -23경도 = -46위도,하지만 난 (때로는) 수신하고 있습니다. 누군가 나에게 무슨 일이 일어나고 있는지에 대한 힌트를 줄 수 있습니까?

답변

0

좋아. 나는 그 해결책을 혼자서 발견했다. 여기에 우리가 간다. 삼각 측량 프로세스는 기본적으로 세 개의 인수를 조합 한 프로세스입니다. 내가 한 몇 가지 검색을 기반으로, 나는 당신이 데이터의 다른 유형의 조합을 사용할 수 있다고 추론한다. 내가 사용한 조합은 타워 ID (장치가 핸드 셰이크 된 타워 이동 장치), 위치 코드 (지역 코드 및 국가 코드) 및 위치 지역 코드와 혼합 된 것입니다. 그래서, 내 새로운 코드는 다음과 같습니다 :이 새로운 코드로

TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); 
GsmCellLocation.requestLocationUpdate(); 
location = (GsmCellLocation) tm.getCellLocation(); 
networkOperator = tm.getNetworkOperator(); 
cellID = location.getCid(); 
lac = location.getLac(); 

public double[] getLocationByMCCMNC(String mcc, String mnc, String lac, String cellId, boolean requestAddress) throws IOException { 

    final String data = "{\"cell_towers\": [{\"location_area_code\": \"" 
     + lac + "\", \"mobile_network_code\": \"" + mnc 
     + "\", \"cell_id\": \"" + cellId 
     + "\", \"mobile_country_code\": \"" + mcc 
     + "\"}], \"version\": \"1.1.0\", \"request_address\": \"" 
     + requestAddress + "\"}"; 

    URL anUrl = new URL("https://www.google.com/loc/json"); 
    HttpURLConnection conn = (HttpURLConnection) anUrl.openConnection(); 

    conn.setRequestMethod("GET"); 
    conn.setDoOutput(true); 
    conn.setDoInput(true); 
    conn.setUseCaches(false); 
    conn.setAllowUserInteraction(false); 
    conn.setRequestProperty("Content-type", "application/jsonrequest"); 

    OutputStream out = conn.getOutputStream(); 
    out.write(data.getBytes()); 
    out.close(); 

    InputStream in = conn.getInputStream(); 

    StringBuilder builder = new StringBuilder(); 
    Reader reader = new InputStreamReader(in); 
    char[] buf = new char[1024]; 
    int read = 0; 
    while ((read = reader.read(buf)) >= 0) { 
     builder.append(String.valueOf(buf, 0, read)); 
    } 
    in.close(); 
    conn.disconnect(); 

    double location[] = new double[2]; 
    try { 
     JSONObject loc = new JSONObject(builder.toString()).getJSONObject("location"); 
     location[0] = Double.valueOf(loc.getDouble("latitude")); 
     location[1] = Double.valueOf(loc.getDouble("longitude")); 
    } catch (JSONException e) { 
     location[0] = -1; 
    location[1] = -1; 
    } 
    return location; 
} 

, 내가 JSON 개체를 반환 구글 위치 JSON 서비스를 사용하고 있습니다. 나는 이것이 매우 트릭적인 문제라고 말하고, 모든 mechams를 이해하기 위해서는 더 많은 것을 탐색 할 필요가 있지만 적어도 이것은 작동 코드이다. 그것이 누군가를 돕기를 바랍니다.

업데이트 : 또한 다음과 같은 문맥에서이 대답을 완성합니다. TRIANGULATION은 모바일 네트워크 (GSM, UMTS, LTE 등)를 통해 무선 액세스를 사용합니다. 나는 지금이 값 변동이 라디오 전파가 환경 (벽, 건물, 인접한 탑 등)에 많은 영향을 미친다는 것을 확신한다.

관련 문제