use of com.fanap.podchat.requestobject.RequestMapReverse in project pod-chat-android-sdk by FanapSoft.
the class ChatCore method mapReverse.
public String mapReverse(RequestMapReverse request) {
String uniqueId = null;
if (chatReady) {
double lat = request.getLat();
double lng = request.getLng();
uniqueId = generateUniqueId();
RetrofitHelperMap retrofitHelperMap = new RetrofitHelperMap("https://api.neshan.org/");
MapApi mapApi = retrofitHelperMap.getService(MapApi.class);
Observable<Response<MapReverse>> observable = mapApi.mapReverse(API_KEY_MAP, lat, lng);
String finalUniqueId = uniqueId;
observable.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(mapReverseResponse -> {
if (mapReverseResponse.isSuccessful()) {
MapReverse mapReverse = mapReverseResponse.body();
if (mapReverse == null) {
captureError(ChatConstant.ERROR_UNKNOWN_EXCEPTION, ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId);
return;
}
ChatResponse<ResultMapReverse> chatResponse = new ChatResponse<>();
ResultMapReverse resultMap = new ResultMapReverse();
String address = mapReverse.getAddress();
if (!Util.isNullOrEmpty(address)) {
resultMap.setAddress(address);
}
resultMap.setCity(mapReverse.getCity());
resultMap.setIn_odd_even_zone(mapReverse.isIn_odd_even_zone());
resultMap.setIn_traffic_zone(mapReverse.isIn_traffic_zone());
resultMap.setMunicipality_zone(mapReverse.getMunicipality_zone());
resultMap.setNeighbourhood(mapReverse.getNeighbourhood());
resultMap.setState(mapReverse.getState());
chatResponse.setUniqueId(finalUniqueId);
chatResponse.setResult(resultMap);
String json = gson.toJson(chatResponse);
listenerManager.callOnMapReverse(json, chatResponse);
showLog("RECEIVE_MAP_REVERSE", json);
} else {
try {
String errorBody;
if (mapReverseResponse.errorBody() != null) {
errorBody = mapReverseResponse.errorBody().string();
JSONObject jObjError = new JSONObject(errorBody);
String errorMessage = jObjError.getString("message");
int errorCode = jObjError.getInt("code");
captureError(errorMessage, errorCode, finalUniqueId);
}
} catch (JSONException e) {
captureError(e.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId, e);
} catch (IOException e) {
captureError(e.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId, e);
}
}
}, (Throwable throwable) -> captureError(throwable.getMessage(), ChatConstant.ERROR_CODE_UNKNOWN_EXCEPTION, finalUniqueId, throwable));
}
return uniqueId;
}
use of com.fanap.podchat.requestobject.RequestMapReverse in project pod-chat-android-sdk by FanapSoft.
the class ChatActivity method mapReverse.
public void mapReverse() {
double lat = 35.7003510;
double lng = 51.3376472;
RequestMapReverse requestMapReverse = new RequestMapReverse.Builder(lat, lng).build();
presenter.mapReverse(requestMapReverse);
}
Aggregations