오프라인지도 상자에서 작업 중입니다. 코드는 정상적으로 맵을 다운로드 할 수 있었지만 맵과 아무 관련이없는 코드 조각을 추가 한 후 다운로드가 중지되고 HTTP401 오류가 발생했습니다. MapboxAccountManager.start를 호출 할 때마다 실패하는 경우가 있습니다. 이 여기에 코드입니다 : 나는 Aysnc 부분을 입력지도 상자 Offlne (Android)
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
DB_Handler db_ansb = new DB_Handler(Init_Carte.this,null,null,1);
// Get data from DB, about the map
HashMap<String, String> data_mapbox = db_ansb.do_get_mapbox(0);
the_mapbox_token = data_mapbox.get("tmapbox_token");
the_mapbox_style = data_mapbox.get("tmapbox_style");
the_mapbox_zoom_min = Integer.parseInt(data_mapbox.get("tmapbox_zoom_min"));
the_mapbox_zoom_max = Integer.parseInt(data_mapbox.get("tmapbox_zoom_max"));
the_mapbox_inter = Double.parseDouble(data_mapbox.get("tmapbox_inter"));
OfflineManager offlineManager = OfflineManager.getInstance(this);
MapboxAccountManager.start(this,the_mapbox_token);
setContentView(R.layout.activity_init_carte);
// Menu with APP compat
// https://developer.android.com/training/appbar/setting-up.html
Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
setSupportActionBar(myToolbar);
// Find our truck GPS position for road map
HashMap<String, String> my_truck = db_ansb.do_get_my_truck();
String str_truck_lagps = my_truck.get("frota_lagps");
String str_truck_logps = my_truck.get("frota_logps");
the_lagps_truck = Double.parseDouble(str_truck_lagps);
the_logps_truck = Double.parseDouble(str_truck_logps);
// Find accident location for road map
HashMap<String, String> my_inter = db_ansb.do_get_inter_resume();
String str_inter_lagps = my_inter.get("inter_lagps");
String str_inter_logps = my_inter.get("inter_logps");
the_lagps_inter = Double.parseDouble(str_inter_lagps);
the_logps_inter = Double.parseDouble(str_inter_logps);
// Compute area to get
HashMap<String, Double> data_gps_inter = db_ansb.do_get_bounds_inter(the_lagps_inter,the_logps_inter,the_mapbox_inter);
final double inter_lagps_ne = data_gps_inter.get("inter_max_lagps"); // Nord Est
final double inter_logps_ne = data_gps_inter.get("inter_max_logps");
final double inter_lagps_so = data_gps_inter.get("inter_min_lagps"); // Sud Ouest
final double inter_logps_so = data_gps_inter.get("inter_min_logps");
// Display what we're doing
tmp_id_msg = (TextView) findViewById(R.id.txt_action);
tmp_id_msg.setText(R.string.str_telechargement_carte);
// Create zone
LatLngBounds latLngBounds = new LatLngBounds.Builder()
.include(new LatLng(inter_lagps_ne, inter_logps_ne)) // Northeast
.include(new LatLng(inter_lagps_so, inter_logps_so)) // Southwest
.build();
OfflineTilePyramidRegionDefinition definition = new OfflineTilePyramidRegionDefinition(
the_mapbox_style,
latLngBounds,
the_mapbox_zoom_min,
the_mapbox_zoom_max,
(Init_Carte.this).getResources().getDisplayMetrics().density);
byte[] metadata;
try
{
JSONObject jsonObject = new JSONObject();
jsonObject.put(JSON_FIELD_REGION_NAME, "Carte");
String json = jsonObject.toString();
metadata = json.getBytes(JSON_CHARSET);
} catch (Exception e)
{
Log.e("TAG", "Failed to encode metadata: " + e.getMessage());
metadata = null;
}
// Get data
offlineManager.createOfflineRegion(definition, metadata, new OfflineManager.CreateOfflineRegionCallback()
{
@Override
public void onCreate(OfflineRegion offlineRegion)
{
offlineRegion.setDownloadState(OfflineRegion.STATE_ACTIVE);
// Monitor the download progress using setObserver
offlineRegion.setObserver(new OfflineRegion.OfflineRegionObserver()
{
@Override
public void onStatusChanged(OfflineRegionStatus status)
{
Log.i("DBUG","onStatusChanged");
// Calculate the download percentage and update the progress bar
double percentage = status.getRequiredResourceCount() >= 0 ?
(100.0 * status.getCompletedResourceCount()/status.getRequiredResourceCount()) :
0.0;
long long_pourcentage = Math.round(percentage);
String str_pourcentage = Long.toString(long_pourcentage)+" %";
// Display on screen
tmp_id_valeur = (TextView) findViewById(R.id.val_action);
tmp_id_valeur.setText(str_pourcentage);
Log.i("DBUG",str_pourcentage+"%");
if (status.isComplete())
{
// OK so now, ask the road
do_get_trajet();
}
}
@Override
public void onError(OfflineRegionError error)
{
// If an error occurs, print to logcat
Log.i("DBUG", "onError reason: " + error.getReason());
Log.e("DBUG", "onError message: " + error.getMessage());
}
@Override
public void mapboxTileCountLimitExceeded(long limit)
{
// Notify if offline region exceeds maximum tile count
Log.i("DBUG", "Mapbox tile count limit exceeded: " + limit);
}
});
}
@Override
public void onError(String error)
{
Log.e("TAG", "Error: " + error);
}
});
}
(str_pourcentage + "%", "DBUG") 3 또는 4 번 Log.i를 얻을; 0 %의 값 다음 I 얻을 얻을 :
를 I/System.out에 [CDS] RX 타임 아웃 : 10000 D/NativeCrypto : SSL = 0x619629c8 sslWrite BUF = 0x41e60068 LEN = 222 write_timeout_millis = 0 D/NativeCrypto : SSL = 0x619629c8 sslRead 버피 = 0x41e60068 렌 = 8192, timeo = 10000 I/DBUG :의 OnError 이유 : REASON_OTHER E가/DBUG :의 OnError 메시지 : HTTP 상태 코드 (401) D/com.mapbox.mapboxsdk.http.HTTPRequest : [HTTP] 응답 코드가 401 인 요청 : 허가되지 않음
수행하는 사실에 따라 다른 페이지에서 동일한 이상한 동작이 나타났습니다. MapboxAccountManager.start 이전의 동작 (this, th e_mapbox_token); 그것은 작동하거나하지 않습니다.
토큰이 정확한지 확인하십시오.
아이디어가 있으십니까?
우리의 DB에 토큰을 변경 한 후에는 확인했지만 짧은 시간 동안 만 : 나는지도의 26 %를 다운로드 할 수 있었다 다음, 나는 다시 HTTP 401 메시지가 ...
몇 가지 질문과 제안 : 사용중인 Mapbox SDK의 버전은 무엇입니까? DB_Handler가 데이터를 가져 오는 위치는? Sqlite 데이터베이스를 사용하는 경우 파일 액세스가 포함되므로 UI 스레드에서 호출해서는 안됩니다. Mapbox 토큰에 대해 반환 된 값을 기록하는 것이 좋습니다.오프라인 영역을 만들고 다운로드를 시작하기 전에 오프라인 데이터베이스에 이미 있는지 확인해야합니다. – Clyde
com.mapbox.mapboxsdk : mapbox-android-sdk : [email protected]를 사용합니다. DB_Handler는 lib 디렉토리에서 가져 와서 SQLLite에서 데이터를 가져옵니다. 그거 아무 문제 없어. SQL 호출은 비동기 내부에 있지 않습니다. 그들은 전에 끝났어. 우리는 다른 활동에서이 지역을 삭제합니다. 그래서 여기에는 창조 만 있습니다. 실제로 우리는 안드로이드가 비동기로 가득차 있기 때문에 lib에 낯선 문제가 있음을 알 수 있습니다. 예를 들어 Lib을 초기화하고 BETORE init가 끝나고 함수를 호출 할 수있는 것 같습니다. 어느 것이 당연히 좋아하지 않습니다 ... 만약에 onStatusChanged를 많이 생각하면, 나는 많은 문제를 겪습니다. 아직도 조사 중 ... 고마워. – Peter