├── .gitignore ├── .idea ├── codeStyles │ ├── Project.xml │ └── codeStyleConfig.xml ├── gradle.xml ├── misc.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE.txt ├── README.md ├── addresspicker ├── .gitignore ├── build.gradle ├── consumer-rules.pro ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── smartlib │ │ └── addresspicker │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── smartlib │ │ │ └── addresspicker │ │ │ └── AddressPickerActivity.kt │ └── res │ │ ├── drawable │ │ ├── ic_gps.xml │ │ └── ic_my_location.xml │ │ ├── layout │ │ └── activity_address_picker.xml │ │ ├── menu │ │ └── menu_home.xml │ │ └── values │ │ ├── attrs.xml │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── smartlib │ └── addresspicker │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── sample ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── picker │ │ └── example │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── picker │ │ │ └── example │ │ │ └── MainActivity.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ ├── ic_launcher_background.xml │ │ └── ic_location.xml │ │ ├── layout │ │ └── activity_main.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── picker │ └── example │ └── ExampleUnitTest.kt ├── sc1.png ├── sc2.png └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | -------------------------------------------------------------------------------- /.idea/codeStyles/Project.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | xmlns:android 17 | 18 | ^$ 19 | 20 | 21 | 22 |
23 |
24 | 25 | 26 | 27 | xmlns:.* 28 | 29 | ^$ 30 | 31 | 32 | BY_NAME 33 | 34 |
35 |
36 | 37 | 38 | 39 | .*:id 40 | 41 | http://schemas.android.com/apk/res/android 42 | 43 | 44 | 45 |
46 |
47 | 48 | 49 | 50 | .*:name 51 | 52 | http://schemas.android.com/apk/res/android 53 | 54 | 55 | 56 |
57 |
58 | 59 | 60 | 61 | name 62 | 63 | ^$ 64 | 65 | 66 | 67 |
68 |
69 | 70 | 71 | 72 | style 73 | 74 | ^$ 75 | 76 | 77 | 78 |
79 |
80 | 81 | 82 | 83 | .* 84 | 85 | ^$ 86 | 87 | 88 | BY_NAME 89 | 90 |
91 |
92 | 93 | 94 | 95 | .* 96 | 97 | http://schemas.android.com/apk/res/android 98 | 99 | 100 | ANDROID_ATTRIBUTE_ORDER 101 | 102 |
103 |
104 | 105 | 106 | 107 | .* 108 | 109 | .* 110 | 111 | 112 | BY_NAME 113 | 114 |
115 |
116 |
117 |
118 | 119 | 121 |
122 |
-------------------------------------------------------------------------------- /.idea/codeStyles/codeStyleConfig.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 20 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 14 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Muhammad Bilal Siddiqui 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AddressPicker 2 | A simple light weight android library to pick address from google map and places API 3 | 4 | ![Alt text](https://github.com/BilalSiddiqui/AddressPicker/blob/master/sc1.png "Pick address") 5 | ![Alt text](https://github.com/BilalSiddiqui/AddressPicker/blob/master/sc2.png "Search in places API") 6 | 7 | Usage: 8 | 9 | Step 1. Add it in your root build.gradle at the end of repositories: 10 | 11 | allprojects { 12 | repositories { 13 | ... 14 | maven { url 'https://jitpack.io' } 15 | } 16 | } 17 | 18 | 19 | Step 2. Add the dependency 20 | 21 | dependencies { 22 | implementation 'com.github.BilalSiddiqui:AddressPicker:Tag' 23 | } 24 | 25 | Step 3. Add Google Places API key in manifest 26 | 27 | 30 | 31 | Step 4. Start address picker activity. 32 | 33 | val intent = Intent(this@MainActivity, AddressPickerActivity::class.java) 34 | intent.putExtra(AddressPickerActivity.ARG_LAT_LNG,MyLatLng(42.5328966, -122.7751082)) 35 | val pinList=ArrayList() 36 | pinList.add(Pin(MyLatLng(42.329989, -122.3100),"Work")) 37 | pinList.add(Pin(MyLatLng(42.023123, -122.23414),"Home")) 38 | intent.putExtra(AddressPickerActivity.ARG_LIST_PIN, pinList) 39 | intent.putExtra(AddressPickerActivity.ARG_ZOOM_LEVEL, 1.0f) 40 | startActivityForResult(intent,REQUEST_ADDRESS ) 41 | 42 | Step 5. Get result in onActivityResult. 43 | 44 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 45 | super.onActivityResult(requestCode, resultCode, data) 46 | if (requestCode == REQUEST_ADDRESS && resultCode == Activity.RESULT_OK) { 47 | val address: Address? = data?.getParcelableExtra(RESULT_ADDRESS) as Address 48 | selected_address.text = 49 | address?.featureName + ", " + address?.locality + ", " + address?.adminArea + ", " + address?.countryName 50 | 51 | } 52 | } 53 | 54 | Features: 55 | 56 | 1- Search in PLACES API. 57 | 58 | 2- Search and select on map. 59 | 60 | 3- Set zoom level of map. 61 | 62 | 4- You can provide list of pin/marker for map to show 63 | 64 | 5- You can provide lat/lng to set initial postion of map through intent extras. 65 | -------------------------------------------------------------------------------- /addresspicker/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /addresspicker/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.library' 2 | apply plugin: 'kotlin-android' 3 | apply plugin: 'kotlin-android-extensions' 4 | android { 5 | compileSdkVersion 28 6 | buildToolsVersion "29.0.2" 7 | 8 | 9 | defaultConfig { 10 | minSdkVersion 16 11 | targetSdkVersion 28 12 | versionCode 1 13 | versionName "1.0" 14 | 15 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 16 | consumerProguardFiles 'consumer-rules.pro' 17 | } 18 | 19 | buildTypes { 20 | release { 21 | minifyEnabled false 22 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 23 | } 24 | } 25 | 26 | } 27 | 28 | dependencies { 29 | implementation fileTree(dir: 'libs', include: ['*.jar']) 30 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 31 | implementation 'androidx.appcompat:appcompat:1.0.2' 32 | implementation 'androidx.core:core-ktx:1.0.2' 33 | implementation 'com.google.android.libraries.places:places:2.0.0' 34 | 35 | implementation 'androidx.legacy:legacy-support-v4:1.0.0' 36 | testImplementation 'junit:junit:4.12' 37 | androidTestImplementation 'androidx.test:runner:1.1.1' 38 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 39 | implementation 'com.google.android.gms:play-services-location:17.0.0' 40 | implementation 'com.google.android.gms:play-services-maps:17.0.0' 41 | implementation 'com.google.android.material:material:1.0.0' 42 | } 43 | -------------------------------------------------------------------------------- /addresspicker/consumer-rules.pro: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BilalSiddiqui/AddressPicker/aeaef429c990328e94c5dee20bd20bad79255ce7/addresspicker/consumer-rules.pro -------------------------------------------------------------------------------- /addresspicker/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class title to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file title. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /addresspicker/src/androidTest/java/com/smartlib/addresspicker/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.smartlib.addresspicker 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.smartlib.addresspicker.test", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /addresspicker/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /addresspicker/src/main/java/com/smartlib/addresspicker/AddressPickerActivity.kt: -------------------------------------------------------------------------------- 1 | package com.smartlib.addresspicker 2 | 3 | import android.Manifest 4 | import android.annotation.SuppressLint 5 | import android.app.Activity 6 | import android.content.Intent 7 | import android.content.IntentSender 8 | import android.content.pm.PackageManager 9 | import android.location.Address 10 | import android.location.Geocoder 11 | import android.location.Location 12 | import android.net.Uri 13 | import android.os.Bundle 14 | import android.os.Looper 15 | import android.provider.Settings 16 | import android.util.Log 17 | import android.view.Menu 18 | import android.view.MenuItem 19 | import android.view.View 20 | import android.widget.Toast 21 | import androidx.appcompat.app.AppCompatActivity 22 | import androidx.core.app.ActivityCompat 23 | import com.google.android.gms.common.api.ApiException 24 | import com.google.android.gms.common.api.ResolvableApiException 25 | import com.google.android.gms.location.* 26 | import com.google.android.gms.maps.CameraUpdateFactory 27 | import com.google.android.gms.maps.GoogleMap 28 | import com.google.android.gms.maps.OnMapReadyCallback 29 | import com.google.android.gms.maps.SupportMapFragment 30 | import com.google.android.gms.maps.model.LatLng 31 | import com.google.android.gms.maps.model.MarkerOptions 32 | import com.google.android.gms.tasks.OnCompleteListener 33 | import com.google.android.gms.tasks.OnFailureListener 34 | import com.google.android.gms.tasks.OnSuccessListener 35 | import com.google.android.gms.tasks.Task 36 | import com.google.android.libraries.places.api.Places 37 | import com.google.android.libraries.places.api.model.Place 38 | import com.google.android.libraries.places.widget.Autocomplete 39 | import com.google.android.libraries.places.widget.AutocompleteActivity 40 | import com.google.android.libraries.places.widget.model.AutocompleteActivityMode 41 | import com.google.android.material.snackbar.Snackbar 42 | import kotlinx.android.synthetic.main.activity_address_picker.* 43 | import java.io.Serializable 44 | import java.text.DateFormat 45 | import java.util.* 46 | 47 | class AddressPickerActivity : AppCompatActivity(), OnMapReadyCallback { 48 | 49 | companion object { 50 | private val TAG = AddressPickerActivity::class.java.simpleName 51 | /** 52 | * Code used in requesting runtime permissions. 53 | */ 54 | private val REQUEST_PERMISSIONS_REQUEST_CODE = 34 55 | private val AUTOCOMPLETE_REQUEST_CODE = 12; 56 | 57 | /** 58 | * Constant used in the location settings dialog. 59 | */ 60 | private val REQUEST_CHECK_SETTINGS = 0x1 61 | 62 | /** 63 | * The desired interval for location updates. Inexact. Updates may be more or less frequent. 64 | */ 65 | private val UPDATE_INTERVAL_IN_MILLISECONDS: Long = 60000 //1 min 66 | private val UPDATE_INTERVAL_IN_MINUTE: Long = 5 * 60 * 1000 //5 mins 67 | 68 | /** 69 | * The fastest rate for active location updates. Exact. Updates will never be more frequent 70 | * than this value. 71 | */ 72 | private val FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS = UPDATE_INTERVAL_IN_MILLISECONDS / 2 73 | 74 | // Keys for storing activity state in the Bundle. 75 | private val KEY_REQUESTING_LOCATION_UPDATES = "requesting-location-updates" 76 | private val KEY_LOCATION = "location" 77 | private val KEY_LAST_UPDATED_TIME_STRING = "last-updated-time-string" 78 | /** 79 | * Send back the selected address*/ 80 | val RESULT_ADDRESS = "address" 81 | 82 | /** 83 | * Initail optional coordinates*/ 84 | val ARG_LAT_LNG = "arg_lat_lng" 85 | 86 | /** 87 | * To show markers on screen*/ 88 | val ARG_LIST_PIN = "list_pins" 89 | 90 | /** 91 | * Set zoom level of map*/ 92 | val ARG_ZOOM_LEVEL = "level_zoom" 93 | } 94 | 95 | private var mMap: GoogleMap? = null 96 | private var mAddress: Address? = null 97 | private var mZoomLevel = 10.0f 98 | private var mDefaultLocation: LatLng? = null 99 | private var mPinList: ArrayList? = null 100 | 101 | /** 102 | * Provides access to the Fused Location Provider API. 103 | */ 104 | private var mFusedLocationClient: FusedLocationProviderClient? = null 105 | 106 | /** 107 | * Provides access to the Location Settings API. 108 | */ 109 | private var mSettingsClient: SettingsClient? = null 110 | 111 | /** 112 | * Stores parameters for requests to the FusedLocationProviderApi. 113 | */ 114 | private var mLocationRequest: LocationRequest? = null 115 | 116 | /** 117 | * Stores the types of location services the client is interested in using. Used for checking 118 | * settings to determine if the device has optimal location settings. 119 | */ 120 | private var mLocationSettingsRequest: LocationSettingsRequest? = null 121 | 122 | /** 123 | * Callback for Location events. 124 | */ 125 | private var mLocationCallback: LocationCallback? = null 126 | 127 | /** 128 | * Represents a geographical location. 129 | */ 130 | private var mCurrentLocation: Location? = null 131 | 132 | /** 133 | * Tracks the status of the location updates request. Value changes when the user presses the 134 | * Start Updates and Stop Updates buttons. 135 | */ 136 | private var mRequestingLocationUpdates: Boolean? = null 137 | 138 | /** 139 | * Time when the location was updated represented as a String. 140 | */ 141 | private var mLastUpdateTime: String? = null 142 | 143 | public override fun onCreate(savedInstanceState: Bundle?) { 144 | super.onCreate(savedInstanceState) 145 | initPlacesApi() 146 | setContentView(R.layout.activity_address_picker) 147 | if (intent.hasExtra(ARG_LAT_LNG)) { 148 | val latLng = 149 | intent.getSerializableExtra(ARG_LAT_LNG) as MyLatLng 150 | mDefaultLocation = 151 | LatLng(latLng.latitude, latLng.longitude) 152 | } 153 | if (intent.hasExtra(ARG_LIST_PIN)) { 154 | mPinList = intent.getSerializableExtra(ARG_LIST_PIN) as ArrayList 155 | } 156 | mZoomLevel = intent.getFloatExtra(ARG_ZOOM_LEVEL, 10.0f) 157 | 158 | 159 | 160 | supportActionBar?.setDisplayHomeAsUpEnabled(true) 161 | setSupportActionBar(toolbar) 162 | mRequestingLocationUpdates = true 163 | mLastUpdateTime = "" 164 | 165 | // Update values using data stored in the Bundle. 166 | updateValuesFromBundle(savedInstanceState) 167 | 168 | mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this) 169 | mSettingsClient = LocationServices.getSettingsClient(this) 170 | 171 | // Kick off the process of building the LocationCallback, LocationRequest, and 172 | // LocationSettingsRequest objects. 173 | createLocationCallback() 174 | createLocationRequest() 175 | buildLocationSettingsRequest() 176 | val mapFragment: SupportMapFragment = 177 | this.supportFragmentManager?.findFragmentById(R.id.map) as SupportMapFragment 178 | mapFragment.getMapAsync(this) 179 | 180 | use_this_location.setOnClickListener { 181 | val intent = Intent() 182 | intent.putExtra(RESULT_ADDRESS, mAddress) 183 | setResult(Activity.RESULT_OK, intent) 184 | finish() 185 | } 186 | 187 | fab_current_location.setOnClickListener { 188 | if (mRequestingLocationUpdates!! && checkPermissions()) { 189 | if (mCurrentLocation != null && mMap != null) { 190 | mMap?.animateCamera( 191 | CameraUpdateFactory.newLatLng( 192 | LatLng( 193 | mCurrentLocation?.latitude!!, 194 | mCurrentLocation?.longitude!! 195 | ) 196 | ) 197 | ) 198 | } else { 199 | startLocationUpdates() 200 | } 201 | } else if (!checkPermissions()) { 202 | requestPermissions() 203 | } 204 | } 205 | } 206 | 207 | private fun initPlacesApi() { 208 | try { 209 | val applicationInfo = getPackageManager().getApplicationInfo( 210 | getPackageName(), 211 | PackageManager.GET_META_DATA 212 | ); 213 | val bundle = applicationInfo.metaData; 214 | val apiKey = bundle.getString("com.google.android.geo.API_KEY"); 215 | if (!apiKey.isNullOrEmpty()) { 216 | // Initialize the SDK 217 | Places.initialize(getApplicationContext(), apiKey); 218 | } 219 | 220 | } catch (e: java.lang.Exception) { 221 | //Resolve error for not existing meta-tag, inform the developer about adding his api key 222 | } 223 | } 224 | 225 | /** 226 | * Updates fields based on data stored in the bundle. 227 | * 228 | * @param savedInstanceState The activity state saved in the Bundle. 229 | */ 230 | private fun updateValuesFromBundle(savedInstanceState: Bundle?) { 231 | if (savedInstanceState != null) { 232 | // Update the value of mRequestingLocationUpdates from the Bundle, and make sure that 233 | // the Start Updates and Stop Updates buttons are correctly enabled or disabled. 234 | if (savedInstanceState.keySet().contains(KEY_REQUESTING_LOCATION_UPDATES)) { 235 | mRequestingLocationUpdates = savedInstanceState.getBoolean( 236 | KEY_REQUESTING_LOCATION_UPDATES 237 | ) 238 | } 239 | 240 | // Update the value of mCurrentLocation from the Bundle and update the UI to show the 241 | // correct latitude and longitude. 242 | if (savedInstanceState.keySet().contains(KEY_LOCATION)) { 243 | // Since KEY_LOCATION was found in the Bundle, we can be sure that mCurrentLocation 244 | // is not null. 245 | mCurrentLocation = savedInstanceState.getParcelable(KEY_LOCATION) 246 | moveMapToLocation( 247 | LatLng( 248 | mCurrentLocation?.latitude!!, 249 | mCurrentLocation?.longitude!! 250 | ) 251 | ) 252 | } 253 | 254 | // Update the value of mLastUpdateTime from the Bundle and update the UI. 255 | if (savedInstanceState.keySet().contains(KEY_LAST_UPDATED_TIME_STRING)) { 256 | mLastUpdateTime = savedInstanceState.getString(KEY_LAST_UPDATED_TIME_STRING) 257 | } 258 | } 259 | } 260 | 261 | override fun onMapReady(googleMap: GoogleMap?) { 262 | startLocationUpdates() 263 | mMap = googleMap; 264 | 265 | if (!mPinList?.isNullOrEmpty()!!) { 266 | for (pin in mPinList!!) { 267 | val options = 268 | MarkerOptions().position(LatLng(pin.latLng.latitude, pin.latLng.longitude)) 269 | if (pin.title?.isNotEmpty()!!) { 270 | options.title(pin.title) 271 | mMap?.addMarker(options) 272 | } 273 | } 274 | } 275 | 276 | if (mDefaultLocation != null) { 277 | moveMapToLocation( 278 | LatLng( 279 | mDefaultLocation?.latitude!!, 280 | mDefaultLocation?.longitude!! 281 | ) 282 | ); 283 | } else if (mCurrentLocation != null) { 284 | mMap?.animateCamera( 285 | CameraUpdateFactory.newLatLng( 286 | LatLng( 287 | mCurrentLocation?.latitude!!, 288 | mCurrentLocation?.longitude!! 289 | ) 290 | ) 291 | ) 292 | } 293 | mMap?.setOnCameraIdleListener { 294 | val midLatLng = mMap?.cameraPosition?.target; 295 | setLocationFromGeoCoder(midLatLng) 296 | } 297 | } 298 | 299 | @SuppressLint("SetTextI18n") 300 | private fun setLocationFromGeoCoder(midLatLng: LatLng?) { 301 | try { 302 | val geo = Geocoder( 303 | applicationContext, 304 | Locale.getDefault() 305 | ); 306 | selected_cordinates.text = 307 | "(" + midLatLng?.latitude!!.toString() + "," + midLatLng.longitude + ")" 308 | 309 | val addresses = 310 | geo.getFromLocation(midLatLng.latitude, midLatLng.longitude, 1); 311 | if (addresses.isEmpty()) { 312 | selected_address.text = "Waiting for Location"; 313 | } else { 314 | if (addresses.size > 0) { 315 | mAddress = addresses[0] 316 | selected_address.text = addresses[0].getAddressLine(0); 317 | //Toast.makeText(getApplicationContext(), "Address:- " + addresses.get(0).getFeatureName() + addresses.get(0).getAdminArea() + addresses.get(0).getLocality(), Toast.LENGTH_LONG).show(); 318 | } 319 | } 320 | } catch (e: java.lang.Exception) { 321 | e.printStackTrace(); // getFromLocation() may sometimes fail 322 | } 323 | } 324 | 325 | 326 | /** 327 | * Sets up the location request. Android has two location request settings: 328 | * `ACCESS_COARSE_LOCATION` and `ACCESS_FINE_LOCATION`. These settings control 329 | * the accuracy of the current location. This sample uses ACCESS_FINE_LOCATION, as defined in 330 | * the AndroidManifest.xml. 331 | * 332 | * 333 | * When the ACCESS_FINE_LOCATION setting is specified, combined with a fast update 334 | * interval (5 seconds), the Fused Location Provider API returns location updates that are 335 | * accurate to within a few feet. 336 | * 337 | * 338 | * These settings are appropriate for mapping applications that show real-time location 339 | * updates. 340 | */ 341 | private fun createLocationRequest() { 342 | mLocationRequest = LocationRequest() 343 | 344 | // Sets the desired interval for active location updates. This interval is 345 | // inexact. You may not receive updates at all if no location sources are available, or 346 | // you may receive them slower than requested. You may also receive updates faster than 347 | // requested if other applications are requesting location at a faster interval. 348 | mLocationRequest!!.setInterval(UPDATE_INTERVAL_IN_MINUTE) 349 | 350 | // Sets the fastest rate for active location updates. This interval is exact, and your 351 | // application will never receive updates faster than this value. 352 | mLocationRequest!!.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS) 353 | 354 | mLocationRequest!!.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY) 355 | } 356 | 357 | /** 358 | * Creates a callback for receiving location events. 359 | */ 360 | private fun createLocationCallback() { 361 | mLocationCallback = object : LocationCallback() { 362 | override fun onLocationResult(locationResult: LocationResult) { 363 | // super.onLocationResult(locationResult) 364 | val isFoundFirstTime = mCurrentLocation == null 365 | mCurrentLocation = locationResult.getLastLocation() 366 | if (isFoundFirstTime && mCurrentLocation != null && mDefaultLocation == null) { 367 | moveMapToLocation( 368 | LatLng( 369 | mCurrentLocation?.latitude!!, 370 | mCurrentLocation?.longitude!! 371 | ) 372 | ) 373 | } 374 | mLastUpdateTime = DateFormat.getTimeInstance().format(Date()) 375 | } 376 | } 377 | } 378 | 379 | /** 380 | * Uses a [com.google.android.gms.location.LocationSettingsRequest.Builder] to build 381 | * a [com.google.android.gms.location.LocationSettingsRequest] that is used for checking 382 | * if a device has the needed location settings. 383 | */ 384 | private fun buildLocationSettingsRequest() { 385 | val builder = LocationSettingsRequest.Builder() 386 | builder.addLocationRequest(mLocationRequest!!) 387 | mLocationSettingsRequest = builder.build() 388 | } 389 | 390 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 391 | when (requestCode) { 392 | // Check for the integer request code originally supplied to startResolutionForResult(). 393 | REQUEST_CHECK_SETTINGS -> when (resultCode) { 394 | Activity.RESULT_OK -> Log.i( 395 | TAG, 396 | "User agreed to make required location settings changes." 397 | ) 398 | Activity.RESULT_CANCELED -> { 399 | Log.i(TAG, "User chose not to make required location settings changes.") 400 | mRequestingLocationUpdates = false 401 | } 402 | }// Nothing to do. startLocationupdates() gets called in onResume again. 403 | 404 | AUTOCOMPLETE_REQUEST_CODE -> { 405 | if (resultCode == RESULT_OK) { 406 | var place = Autocomplete.getPlaceFromIntent(data!!); 407 | moveMapToLocation(place.latLng!!) 408 | selected_address?.text = place.address 409 | Log.i(TAG, "Place: " + place.getName() + ", " + place.getId()); 410 | } else if (resultCode == AutocompleteActivity.RESULT_ERROR) { 411 | // TODO: Handle the error. 412 | var status = Autocomplete.getStatusFromIntent(data!!); 413 | Log.i(TAG, status.getStatusMessage()); 414 | } else if (resultCode == RESULT_CANCELED) { 415 | // The user canceled the operation. 416 | } 417 | } 418 | 419 | } 420 | } 421 | 422 | private fun moveMapToLocation(latLng: LatLng) { 423 | val center = CameraUpdateFactory.newLatLng(latLng) 424 | val zoom = CameraUpdateFactory.zoomTo(mZoomLevel) 425 | mMap?.moveCamera(zoom) 426 | mMap?.moveCamera(center) 427 | } 428 | 429 | 430 | /** 431 | * Requests location updates from the FusedLocationApi. Note: we don't call this unless location 432 | * runtime permission has been granted. 433 | */ 434 | private fun startLocationUpdates() { 435 | // Begin by checking if the device has the necessary location settings. 436 | mSettingsClient!!.checkLocationSettings(mLocationSettingsRequest) 437 | .addOnSuccessListener(this, object : OnSuccessListener { 438 | override fun onSuccess(locationSettingsResponse: LocationSettingsResponse) { 439 | Log.i(TAG, "All location settings are satisfied.") 440 | 441 | 442 | mFusedLocationClient!!.requestLocationUpdates( 443 | mLocationRequest, 444 | mLocationCallback, Looper.myLooper() 445 | ) 446 | mRequestingLocationUpdates = true 447 | } 448 | }) 449 | .addOnFailureListener(this, object : OnFailureListener { 450 | override fun onFailure(e: Exception) { 451 | val statusCode = (e as ApiException).getStatusCode() 452 | when (statusCode) { 453 | LocationSettingsStatusCodes.RESOLUTION_REQUIRED -> { 454 | Log.i( 455 | TAG, 456 | "Location settings are not satisfied. Attempting to upgrade " + "location settings " 457 | ) 458 | try { 459 | // Show the dialog by calling startResolutionForResult(), and check the 460 | // result in onActivityResult(). 461 | val rae = e as ResolvableApiException 462 | rae.startResolutionForResult( 463 | this@AddressPickerActivity, 464 | REQUEST_CHECK_SETTINGS 465 | ) 466 | } catch (sie: IntentSender.SendIntentException) { 467 | Log.i(TAG, "PendingIntent unable to execute request.") 468 | } 469 | 470 | } 471 | LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE -> { 472 | val errorMessage = 473 | "Location settings are inadequate, and cannot be " + "fixed here. Fix in Settings." 474 | Log.e(TAG, errorMessage) 475 | Toast.makeText( 476 | this@AddressPickerActivity, 477 | errorMessage, 478 | Toast.LENGTH_LONG 479 | ) 480 | .show() 481 | mRequestingLocationUpdates = false 482 | } 483 | } 484 | 485 | } 486 | }) 487 | } 488 | 489 | /** 490 | * Removes location updates from the FusedLocationApi. 491 | */ 492 | private fun stopLocationUpdates() { 493 | if ((!mRequestingLocationUpdates!!)) { 494 | Log.d(TAG, "stopLocationUpdates: updates never requested, no-op.") 495 | return 496 | } 497 | 498 | // It is a good practice to remove location requests when the activity is in a paused or 499 | // stopped state. Doing so helps battery performance and is especially 500 | // recommended in applications that request frequent location updates. 501 | mFusedLocationClient!!.removeLocationUpdates(mLocationCallback) 502 | .addOnCompleteListener(this, object : OnCompleteListener { 503 | override fun onComplete(task: Task) { 504 | mRequestingLocationUpdates = false 505 | } 506 | }) 507 | } 508 | 509 | 510 | override fun onCreateOptionsMenu(menu: Menu): Boolean { 511 | val menuInflater = getMenuInflater() 512 | menuInflater.inflate(R.menu.menu_home, menu); 513 | return super.onCreateOptionsMenu(menu); 514 | } 515 | 516 | override fun onOptionsItemSelected(item: MenuItem?): Boolean { 517 | if (item?.itemId == R.id.action_search) { 518 | 519 | var fields: List = Arrays.asList( 520 | Place.Field.ID, 521 | Place.Field.NAME, 522 | Place.Field.LAT_LNG, 523 | Place.Field.ADDRESS 524 | ) 525 | 526 | var intent: Intent = Autocomplete.IntentBuilder( 527 | AutocompleteActivityMode.FULLSCREEN, fields 528 | ) 529 | .build(this); 530 | startActivityForResult(intent, AUTOCOMPLETE_REQUEST_CODE); 531 | 532 | } 533 | return super.onOptionsItemSelected(item) 534 | } 535 | 536 | public override fun onResume() { 537 | super.onResume() 538 | // Within {@code onPause()}, we remove location updates. Here, we resume receiving 539 | // location updates if the user has requested them. 540 | if (mRequestingLocationUpdates!! && checkPermissions()) { 541 | startLocationUpdates() 542 | } 543 | } 544 | 545 | override fun onPause() { 546 | super.onPause() 547 | 548 | // Remove location updates to save battery. 549 | stopLocationUpdates() 550 | } 551 | 552 | /** 553 | * Stores activity data in the Bundle. 554 | */ 555 | public override fun onSaveInstanceState(savedInstanceState: Bundle) { 556 | savedInstanceState.putBoolean(KEY_REQUESTING_LOCATION_UPDATES, mRequestingLocationUpdates!!) 557 | savedInstanceState.putParcelable(KEY_LOCATION, mCurrentLocation) 558 | savedInstanceState.putString(KEY_LAST_UPDATED_TIME_STRING, mLastUpdateTime) 559 | super.onSaveInstanceState(savedInstanceState) 560 | } 561 | 562 | /** 563 | * Shows a [Snackbar]. 564 | * 565 | * @param mainTextStringId The id for the string resource for the Snackbar text. 566 | * @param actionStringId The text of the action item. 567 | * @param listener The listener associated with the Snackbar action. 568 | */ 569 | private fun showSnackbar( 570 | mainTextStringId: Int, actionStringId: Int, 571 | listener: View.OnClickListener 572 | ) { 573 | Snackbar.make( 574 | findViewById(android.R.id.content), 575 | getString(mainTextStringId), 576 | Snackbar.LENGTH_INDEFINITE 577 | ) 578 | .setAction(getString(actionStringId), listener).show() 579 | } 580 | 581 | /** 582 | * Return the current state of the permissions needed. 583 | */ 584 | private fun checkPermissions(): Boolean { 585 | val permissionState = ActivityCompat.checkSelfPermission( 586 | this, 587 | Manifest.permission.ACCESS_FINE_LOCATION 588 | ) 589 | return permissionState == PackageManager.PERMISSION_GRANTED 590 | } 591 | 592 | private fun requestPermissions() { 593 | val shouldProvideRationale = ActivityCompat.shouldShowRequestPermissionRationale( 594 | this, 595 | Manifest.permission.ACCESS_FINE_LOCATION 596 | ) 597 | 598 | // Provide an additional rationale to the user. This would happen if the user denied the 599 | // request previously, but didn't check the "Don't ask again" checkbox. 600 | if (shouldProvideRationale) { 601 | Log.i(TAG, "Displaying permission rationale to provide additional context.") 602 | showSnackbar(R.string.permission_rationale, 603 | android.R.string.ok, View.OnClickListener { 604 | // Request permission 605 | ActivityCompat.requestPermissions( 606 | this@AddressPickerActivity, 607 | arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 608 | REQUEST_PERMISSIONS_REQUEST_CODE 609 | ) 610 | }) 611 | } else { 612 | Log.i(TAG, "Requesting permission") 613 | // Request permission. It's possible this can be auto answered if device policy 614 | // sets the permission in a given state or the user denied the permission 615 | // previously and checked "Never ask again". 616 | ActivityCompat.requestPermissions( 617 | this@AddressPickerActivity, 618 | arrayOf(Manifest.permission.ACCESS_FINE_LOCATION), 619 | REQUEST_PERMISSIONS_REQUEST_CODE 620 | ) 621 | } 622 | } 623 | 624 | /** 625 | * Callback received when a permissions request has been completed. 626 | */ 627 | override fun onRequestPermissionsResult( 628 | requestCode: Int, permissions: Array, 629 | grantResults: IntArray 630 | ) { 631 | Log.i(TAG, "onRequestPermissionResult") 632 | if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE) { 633 | if (grantResults.size <= 0) { 634 | // If user interaction was interrupted, the permission request is cancelled and you 635 | // receive empty arrays. 636 | Log.i(TAG, "User interaction was cancelled.") 637 | } else if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { 638 | Log.i(TAG, "Permission granted, updates requested, starting location updates") 639 | startLocationUpdates() 640 | } else { 641 | // Permission denied. 642 | 643 | // Notify the user via a SnackBar that they have rejected a core permission for the 644 | // app, which makes the Activity useless. In a real app, core permissions would 645 | // typically be best requested during a welcome-screen flow. 646 | 647 | // Additionally, it is important to remember that a permission might have been 648 | // rejected without asking the user for permission (device policy or "Never ask 649 | // again" prompts). Therefore, a user interface affordance is typically implemented 650 | // when permissions are denied. Otherwise, your app could appear unresponsive to 651 | // touches or interactions which have required permissions. 652 | showSnackbar(R.string.permission_denied_explanation, 653 | R.string.settings, View.OnClickListener { 654 | // Build intent that displays the App settings screen. 655 | val intent = Intent() 656 | intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS 657 | val uri = Uri.fromParts( 658 | "package", 659 | BuildConfig.APPLICATION_ID, null 660 | ) 661 | intent.data = uri 662 | intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK 663 | startActivity(intent) 664 | }) 665 | } 666 | } 667 | } 668 | } 669 | 670 | class MyLatLng(var latitude: Double, var longitude: Double) : Serializable 671 | class Pin(var latLng: com.smartlib.addresspicker.MyLatLng, var title: String?) : Serializable 672 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/drawable/ic_gps.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/drawable/ic_my_location.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/layout/activity_address_picker.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 23 | 24 | 25 | 26 | 29 | 30 | 36 | 37 | 38 | 45 | 46 | 57 | 58 | 63 | 64 | 68 | 69 | 78 | 79 | 80 | 87 | 88 | 101 | 102 | 103 | 104 | 105 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/menu/menu_home.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 10 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #66000000 4 | 5 | 6 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16dp 4 | 16dp 5 | 6 | 16sp 7 | 8 | 10dp 9 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | AddressPicker 3 | 4 | 5 | Latitude 6 | Longitude 7 | Last location update time 8 | 9 | Start updates 10 | Stop updates 11 | 12 | The location settings on the device are not 13 | adequate to run this sample. Fix in Settings. 14 | 15 | Location permission is needed for core functionality 16 | Permission was denied, but is needed for core 17 | functionality. 18 | Settings 19 | Pick Address 20 | Please enable location from settings 21 | Enable 22 | Search 23 | Use this Location 24 | 25 | -------------------------------------------------------------------------------- /addresspicker/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /addresspicker/src/test/java/com/smartlib/addresspicker/ExampleUnitTest.kt: -------------------------------------------------------------------------------- 1 | package com.smartlib.addresspicker 2 | 3 | import org.junit.Test 4 | 5 | import org.junit.Assert.* 6 | 7 | /** 8 | * Example local unit test, which will execute on the development machine (host). 9 | * 10 | * See [testing documentation](http://d.android.com/tools/testing). 11 | */ 12 | class ExampleUnitTest { 13 | @Test 14 | fun addition_isCorrect() { 15 | assertEquals(4, 2 + 2) 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | ext.kotlin_version = '1.3.41' 5 | repositories { 6 | google() 7 | jcenter() 8 | 9 | } 10 | dependencies { 11 | classpath 'com.android.tools.build:gradle:3.5.0' 12 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" 13 | // NOTE: Do not place your application dependencies here; they belong 14 | // in the individual module build.gradle files 15 | } 16 | } 17 | 18 | allprojects { 19 | repositories { 20 | google() 21 | jcenter() 22 | 23 | } 24 | } 25 | 26 | task clean(type: Delete) { 27 | delete rootProject.buildDir 28 | } 29 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | # IDE (e.g. Android Studio) users: 3 | # Gradle settings configured through the IDE *will override* 4 | # any settings specified in this file. 5 | # For more details on how to configure your build environment visit 6 | # http://www.gradle.org/docs/current/userguide/build_environment.html 7 | # Specifies the JVM arguments used for the daemon process. 8 | # The setting is particularly useful for tweaking memory settings. 9 | org.gradle.jvmargs=-Xmx1536m 10 | # When configured, Gradle will run in incubating parallel mode. 11 | # This option should only be used with decoupled projects. More details, visit 12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 13 | # org.gradle.parallel=true 14 | # AndroidX package structure to make it clearer which packages are bundled with the 15 | # Android operating system, and which are packaged with your app's APK 16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 17 | android.useAndroidX=true 18 | # Automatically convert third-party libraries to use AndroidX 19 | android.enableJetifier=true 20 | # Kotlin code style for this project: "official" or "obsolete": 21 | kotlin.code.style=official 22 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/BilalSiddiqui/AddressPicker/aeaef429c990328e94c5dee20bd20bad79255ce7/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Tue Aug 27 06:07:28 PKT 2019 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /sample/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /sample/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | apply plugin: 'kotlin-android' 4 | 5 | apply plugin: 'kotlin-android-extensions' 6 | 7 | android { 8 | compileSdkVersion 28 9 | buildToolsVersion "29.0.2" 10 | defaultConfig { 11 | applicationId "com.picker.example" 12 | minSdkVersion 16 13 | targetSdkVersion 28 14 | versionCode 1 15 | versionName "1.0" 16 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 17 | } 18 | buildTypes { 19 | release { 20 | minifyEnabled false 21 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 22 | } 23 | } 24 | } 25 | 26 | dependencies { 27 | implementation fileTree(dir: 'libs', include: ['*.jar']) 28 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" 29 | implementation 'androidx.appcompat:appcompat:1.0.2' 30 | implementation 'androidx.core:core-ktx:1.0.2' 31 | implementation 'androidx.constraintlayout:constraintlayout:1.1.3' 32 | 33 | testImplementation 'junit:junit:4.12' 34 | androidTestImplementation 'androidx.test:runner:1.1.1' 35 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' 36 | implementation project(path: ':addresspicker') 37 | } 38 | -------------------------------------------------------------------------------- /sample/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class title to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file title. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /sample/src/androidTest/java/com/picker/example/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.picker.example 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.storeonline.addresssample", appContext.packageName) 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /sample/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 13 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /sample/src/main/java/com/picker/example/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.picker.example 2 | 3 | import android.app.Activity 4 | import android.content.Intent 5 | import android.location.Address 6 | import android.os.Bundle 7 | import androidx.appcompat.app.AppCompatActivity 8 | import com.smartlib.addresspicker.AddressPickerActivity 9 | import com.smartlib.addresspicker.AddressPickerActivity.Companion.RESULT_ADDRESS 10 | import com.smartlib.addresspicker.MyLatLng 11 | import com.smartlib.addresspicker.Pin 12 | import kotlinx.android.synthetic.main.activity_main.* 13 | 14 | 15 | class MainActivity : AppCompatActivity() { 16 | companion object { 17 | val REQUEST_ADDRESS = 132 18 | } 19 | 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | setContentView(R.layout.activity_main) 23 | get_address?.setOnClickListener { 24 | val intent = Intent(this@MainActivity, AddressPickerActivity::class.java) 25 | intent.putExtra(AddressPickerActivity.ARG_LAT_LNG,MyLatLng(42.5328966, -122.7751082)) 26 | val pinList=ArrayList() 27 | pinList.add(Pin(MyLatLng(42.329989, -122.3100),"Work")) 28 | pinList.add(Pin(MyLatLng(42.023123, -122.23414),"Home")) 29 | intent.putExtra(AddressPickerActivity.ARG_LIST_PIN, pinList) 30 | intent.putExtra(AddressPickerActivity.ARG_ZOOM_LEVEL, 1.0f) 31 | startActivityForResult( 32 | intent, 33 | REQUEST_ADDRESS 34 | ) 35 | } 36 | } 37 | 38 | override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { 39 | super.onActivityResult(requestCode, resultCode, data) 40 | if (requestCode == REQUEST_ADDRESS && resultCode == Activity.RESULT_OK) { 41 | val address: Address? = data?.getParcelableExtra(RESULT_ADDRESS) as Address 42 | selected_address.text = 43 | address?.featureName + ", " + address?.locality + ", " + address?.adminArea + ", " + address?.countryName 44 | 45 | } 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 12 | 13 | 19 | 22 | 25 | 26 | 27 | 28 | 34 | 35 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /sample/src/main/res/drawable/ic_location.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /sample/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 15 | 16 |