Created
September 18, 2019 05:28
-
-
Save vitalyfedorov/2854d5541e0be7481cab39b84f6680e2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Использование во fragment | |
| MapUtils.initGoogleMap(map) { googleMap -> | |
| MapUtils.setupMap(context, googleMap, handlePointsCallback) | |
| } | |
| class MapUtils { | |
| companion object { | |
| //Получаем карту. Callback вызывается в UI потоке | |
| fun initGoogleMap( | |
| map: CustomMapFragment, | |
| callback: (googleMap: GoogleMap) -> Unit | |
| ) { | |
| map.getMapAsync { googleMap -> | |
| callback(googleMap) | |
| } | |
| } | |
| //Добавить метки на карту | |
| fun setupMap( | |
| ctx: Context, | |
| googleMap: GoogleMap, | |
| addresses: ArrayList<String>, | |
| callback: (points: ArrayList<LatLng>) -> Unit | |
| ) { | |
| //Вызываем Geocoder в отдельном потоке | |
| doAsync { | |
| val points = getLatLngFromGeocoder(ctx, addresses) | |
| //Только после получения координат добавляем их на карту, обязательно в UI потоке | |
| uiThread { | |
| addRouteOnMap(googleMap, points, addresses) | |
| callback(points) | |
| } | |
| } | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment