diff --git a/README.md b/README.md index 20285b9..8b3bc83 100755 --- a/README.md +++ b/README.md @@ -1,33 +1,22 @@ [![](https://jitpack.io/v/li2/android-place.svg)](https://jitpack.io/#li2/android-place) -## Google Place Autocomplete & Search in Rx +# Geography Library - Android -This library is a wrapper of Google Place SDK in Rx: +A library to wrap Google Place Autocomplete SDK, also get last known location in Rx to break with the OnActivityResult and callback implementation. -- Two options to search place: - - Option 1: Launch built-in autocomplete activity - - Option 2: Get place predictions programmatically -- Use Rx to break with the OnActivityResult and callback implementation. -- Geocoder to get address components from latLng and address full name. +Usage sample: [MainFragment](https://github.com/li2/android-place/blob/master/app/src/main/java/me/li2/android/placesample/MainFragment.kt) -android-form-validation +## Usage - Google Place Autocomplete -Further reading https://medium.com/@li2/android-practice-google-place-autocomplete-search-in-rx-79686271d840 +Two options to search place by Google Place SDK: +- Option 1: Launch built-in autocomplete activity +- Option 2: Get place predictions programmatically -## Android Last Known Location (location permission and service) - -This library provices -- Rx way to request location permission and service, -- Rx way to get last known location, -- Extension functions to open system location settings and App settings page. - - -## Usage - -[MainFragment](https://github.com/li2/android-place/blob/master/app/src/main/java/me/li2/android/placesample/MainFragment.kt) +Further reading [https://medium.com/@li2/android-practice-google-place-autocomplete-search-in-rx-79686271d840](https://medium.com/@li2/android-practice-google-place-autocomplete-search-in-rx-79686271d840) +android-form-validation ```kotlin val placeAutoComplete = PlaceAutoComplete(context, context.getString(R.string.google_api_key)) @@ -43,7 +32,23 @@ placeAutoComplete.getPlacePredictions(query) .subscribeBy(onNext = { predictions: List -> }, onError = { }) +``` + +## Usage - Geocoder address components + +```kotlin +fun getAddressComponents(context: Context, lat: Double, lng: Double): AddressComponents? +fun getAddressComponents(context: Context, addressName: String): AddressComponents? +``` + +## Usage - Last Known Location + +- Rx way to request location permission and service, +- Rx way to get last known location, +- Extension functions to open system location settings and App settings page. + +```kotlin activity?.ifLocationAllowed(onError = { toast(it.message.toString()) }, onResult = { result: RequestLocationResult -> @@ -53,7 +58,9 @@ activity?.ifLocationAllowed(onError = { // it's good time to get last know location requestLastKnownLocation() } - RequestLocationResult.PERMISSION_DENIED, + RequestLocationResult.PERMISSION_DENIED -> { + toast("permission denied") + } RequestLocationResult.PERMISSION_DENIED_NOT_ASK_AGAIN -> { // location permission denied, go to App settings activity?.openAppSettings(context.packageName) @@ -65,13 +72,30 @@ activity?.ifLocationAllowed(onError = { } }) -LastKnownLocationUtils.requestLastKnownLocation(context) - .subscribeBy(onNext = { location -> - GeocoderUtils.getAddressComponents(context, location.latitude, location.longitude) - }, onError = { exception -> - }) +private fun requestLastLocation() { + LastKnownLocationUtils.requestLastKnownLocation(context) + .subscribeBy(onNext = { location -> + GeocoderUtils.getAddressComponents(context, location.latitude, location.longitude) + }, onError = { exception -> + }) +} ``` +## Usage - Map + +```kotlin +val marker1 = MarkerInfo("blue", listOf("62.107733,-145.5419"), 'S') +val marker2 = MarkerInfo("yellow", listOf("Tok, AK"), 'C', icon = "https://raw.githubusercontent.com/li2/android-geography/master/panda.png") +val marker3 = MarkerInfo("green", listOf("Delta Junction, AK"), size = MarkerInfo.MarkerSize.TINY) +generateMapStaticImageUrl( + apiKey = apiKey, + central = "63.259591,-144.667969", + mapType = MapType.SATELLITE, + markers = listOf(marker1, marker2, marker3), + size = "400x400", + zoomLevel = 6) +``` +static-map-image ## Download @@ -83,7 +107,6 @@ implementation 'com.github.li2.android-geography:place:latest_version' ``` - ## License ``` diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..b849713 --- /dev/null +++ b/_config.yml @@ -0,0 +1 @@ +theme: jekyll-theme-leap-day \ No newline at end of file diff --git a/place_autocomplete.gif b/screenshots/place_autocomplete.gif similarity index 100% rename from place_autocomplete.gif rename to screenshots/place_autocomplete.gif diff --git a/screenshots/static-map-image.png b/screenshots/static-map-image.png new file mode 100644 index 0000000..b74186e Binary files /dev/null and b/screenshots/static-map-image.png differ