| | |
| | | import android.util.Log |
| | | import android.view.View |
| | | import androidx.core.content.ContextCompat |
| | | import cn.sinata.rxnetty.LogHelper |
| | | import cn.sinata.xldutils.utils.SPUtils |
| | | import com.driver.igotrip.R |
| | | import com.driver.igotrip.base.Const |
| | |
| | | import com.google.android.gms.maps.model.Polyline |
| | | import com.google.android.gms.maps.model.PolylineOptions |
| | | import com.google.gson.Gson |
| | | import com.tbruyelle.rxpermissions2.RxPermissions |
| | | import io.reactivex.Observable |
| | | import io.reactivex.android.schedulers.AndroidSchedulers |
| | | import io.reactivex.schedulers.Schedulers |
| | | import okhttp3.MediaType.Companion.toMediaTypeOrNull |
| | | import okhttp3.OkHttpClient |
| | | import okhttp3.Request |
| | |
| | | |
| | | |
| | | fun initMap(mapView: SupportMapFragment, function: (GoogleMap) -> Unit) { |
| | | mapView.getMapAsync { p0 -> |
| | | val mMyLocationStyle = GoogleMapOptions() |
| | | p0.uiSettings.isMyLocationButtonEnabled = false |
| | | p0.setMinZoomPreference(6.0f); |
| | | p0.setMaxZoomPreference(16.0f); |
| | | // mMyLocationStyle.interval(5000) |
| | | // mMyLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER) |
| | | // mMyLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.gps_point)) |
| | | // p0.setLocationSource() = mMyLocationStyle |
| | | // p0.isMyLocationEnabled = false |
| | | // p0.animateCamera(CameraUpdateFactory.zoomTo(aMap.maxZoomLevel - 3)) |
| | | // 设置定位的类型为定位模式,有定位、跟随或地图根据面向方向旋转几种 |
| | | // p0.setMyLocationType(GoogleMap.LOCATION_TYPE_LOCATE) |
| | | // val uiSettings: UiSettings = aMap.uiSettings |
| | | // uiSettings.isZoomControlsEnabled = false |
| | | function(p0) |
| | | } |
| | | |
| | | val subscribe = |
| | | RxPermissions(mapView.requireActivity()).request(Manifest.permission.ACCESS_FINE_LOCATION) |
| | | .subscribe { |
| | | if (it) { |
| | | mapView.getMapAsync { p0 -> |
| | | val mMyLocationStyle = GoogleMapOptions() |
| | | p0.uiSettings.isMyLocationButtonEnabled = false |
| | | p0.setMinZoomPreference(6.0f); |
| | | p0.setMaxZoomPreference(16.0f); |
| | | // mMyLocationStyle.interval(5000) |
| | | // mMyLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER) |
| | | // mMyLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.mipmap.gps_point)) |
| | | // p0.setLocationSource() = mMyLocationStyle |
| | | // p0.isMyLocationEnabled = false |
| | | // p0.animateCamera(CameraUpdateFactory.zoomTo(aMap.maxZoomLevel - 3)) |
| | | // 设置定位的类型为定位模式,有定位、跟随或地图根据面向方向旋转几种 |
| | | // p0.setMyLocationType(GoogleMap.LOCATION_TYPE_LOCATE) |
| | | // val uiSettings: UiSettings = aMap.uiSettings |
| | | // uiSettings.isZoomControlsEnabled = false |
| | | function(p0) |
| | | } |
| | | } else { |
| | | Log.e("map", "没有权限") |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | |
| | | return false |
| | | } |
| | | |
| | | fun getClient(url: String, function: (String) -> Unit) { |
| | | fun getClient(url: String, retryCount: Int = 3, function: (String) -> Unit) { |
| | | val client = OkHttpClient().newBuilder().build() |
| | | val mediaType = "text/plain".toMediaTypeOrNull() |
| | | val body = RequestBody.create(mediaType, "") |
| | | val request: Request = Request.Builder() |
| | | .url(url) |
| | | .method("GET", null) |
| | | .build() |
| | | Thread { |
| | | try { |
| | | val response = client.newCall(request).execute() |
| | | Handler(Looper.getMainLooper()).post { |
| | | function(response.body?.string() ?: "") |
| | | LogHelper.logRecord("请求谷歌服务器 $url") |
| | | val subscribe = Observable.just(request) |
| | | .map { request -> client.newCall(request).execute().body?.string() ?: "" } |
| | | .retry(retryCount.toLong()) // 最多额外重试 3 次(加上首次共 4 次尝试) |
| | | .subscribeOn(Schedulers.io()) |
| | | .observeOn(AndroidSchedulers.mainThread()) |
| | | .subscribe({ |
| | | try { |
| | | if (it.isEmpty()) { |
| | | LogHelper.logRecord("请求谷歌服务器成功 获取结果异常为空") |
| | | return@subscribe |
| | | } |
| | | function(it) |
| | | LogHelper.logRecord("请求谷歌服务器成功") |
| | | } catch (e: Exception) { |
| | | e.printStackTrace() |
| | | LogHelper.logRecord("请求谷歌服务器成功,获取结果异常报错 message:${e.message},stackTrace:${e.stackTraceToString()}") |
| | | } |
| | | } catch (e: Exception) { |
| | | e.printStackTrace() |
| | | } |
| | | }.start() |
| | | |
| | | }, { throwable -> |
| | | throwable.printStackTrace() |
| | | LogHelper.logRecord("请求谷歌服务器异常报错 message:${throwable.message},stackTrace:${throwable.stackTraceToString()}") |
| | | }) |
| | | } |
| | | |
| | | /*** |