投稿時間:2022-09-03 11:13:00 RSSフィード2022-09-03 11:00 分まとめ(13件)

カテゴリー等 サイト名等 記事タイトル・トレンドワード等 リンクURL 頻出ワード・要約等/検索ボリューム 登録日
IT 気になる、記になる… 【週末限定セール】M2チップ搭載「MacBook Air」のCTOモデルが最大13,000円オフに − ヤマダウェブコム https://taisy0.com/2022/09/03/160896.html macbook 2022-09-03 01:46:49
python Pythonタグが付けられた新着投稿 - Qiita Pythonでcsvにスペース区切りのリストを書き込む https://qiita.com/Yuji-207/items/c1bf8e4f08f58870f764 hogepyl 2022-09-03 10:43:04
海外TECH DEV Community Simple Google Map App - Jetpack Compose https://dev.to/vtsen/simple-google-map-app-jetpack-compose-2ebb Simple Google Map App Jetpack ComposeStep by step guides to implement Google Map app using Jetpack Compose components for the Android Maps SDKThis article was originally published at vtsen hashnode dev on Aug This simple Google Map app is based on the simplified version of sample app from this Google Map compose library In addition I added the following features into this sample app Location Permission Request Device Location Setting Request Setup Google Cloud ProjectThe first thing you need to do is setting up a Google cloud project to generate an API key which allows you to use the Google Maps SDK API Setup New Project in console cloud google comIn your project dashboard go to APIs overviewIn API amp Services page go to LibrarySearch for Maps SDK for Android and enable itBack to the API amp Services page go to CredentialsSelect CREATE CREDENTIALS then select API keyThe API key is now generated Click on the API Key to edit it You can rename the API key name to whatever you like For this sample app purpose you do not need to set any restrictions on this API key Select None for Application restrictionsSelect Don t restrict key for API restrictionsThese are just brief instructions For detailed official instructions see below Set Up in the Google Cloud ConsoleUsing API keysPlease note I haven t setup any billing account or enable billing and it still works Once you have the API key it is time to implement the code Add dependencies in build gradleThese are the libraries needed to use Google Map compose library implementation com google maps android maps compose implementation com google android gms play services maps implementation androidx compose foundation foundation beta Setup Secrets Gradle PluginSecrets Gradle Plugin is basically a library to help you hide your API key without committing it to the version control system It allows you to define your variable e g API key in the local properties file which is not checked into version control and retrieve the variable For example you can retrieve the variable in the AndroidManifest xml file These are the steps to add the Secrets Gradle plugin In project level build gradle buildscript dependencies classpath com google android libraries mapsplatform secrets gradle plugin secrets gradle plugin In app level build gradle plugins id com google android libraries mapsplatform secrets gradle plugin Add MAPS API KEY in local propertiesIn local properties file copy the API key you get from Setup Google Cloud Project steps above and paste it here MAPS API KEY Your API Key here Add meta data in AndroidManifest xmlIn order to read the MAPS API KEY variable that you defined in local properties you need to add the lt meta data gt in the AndroidManifext xml Add this lt meta data gt tag within the lt application gt tag lt application lt meta data android name com google android geo API KEY android value MAPS API KEY gt lt application gt If you do not setup Secrets Gradle plugin above you will get this error Attribute meta data com google android geo API KEY value at AndroidManifest xml requires a placeholder substitution but no value for lt MAPS API KEY gt is provided Add Internet and Location PermissionsSince the app needs to access internet and location permissions we add these permissions in the AndroidManifest xml lt manifest xmlns android gt lt uses permission android name android permission INTERNET gt lt uses permission android name android permission ACCESS FINE LOCATION gt lt uses permission android name android permission ACCESS COARSE LOCATION gt lt manifest gt Implement GoogleMap and Marker GoogleMap and Marker are the composable functions from the library that we can call to show the map and the markers on the map The map shows the current position if available and it is defaulted to Sydney Composable private fun MyGoogleMap currentLocation Location cameraPositionState CameraPositionState onGpsIconClick gt Unit val mapUiSettings by remember mutableStateOf MapUiSettings zoomControlsEnabled false GoogleMap modifier Modifier fillMaxSize cameraPositionState cameraPositionState uiSettings mapUiSettings Marker state MarkerState position LocationUtils getPosition currentLocation title Current Position GpsIconButton onIconClick onGpsIconClick DebugOverlay cameraPositionState By default the zoom control is on To turn it off you create a new MapUiSettings and pass that into the GoogleMap as parameter The map also have GPS icon When you click on it it moves the camera to the current location It also requests location permission and to enable device location setting if those requests have not been granted before DebugOverlay just an overlay screen to show the current camera status and position Request Location PermissionTo check whether the location permission has already been granted you use ContextCompat checkSelfPermission API fun isLocationPermissionGranted context Context Boolean return ContextCompat checkSelfPermission context Manifest permission ACCESS FINE LOCATION PackageManager PERMISSION GRANTED If the location permission is not granted you setup the callback whether the permission is granted or denied using rememberLauncherForActivityResult with ActivityResultContracts RequestPermission To request the location permission using you call the ActivityResultLauncher launch Composable fun LocationPermissionsDialog onPermissionGranted gt Unit onPermissionDenied gt Unit val requestLocationPermissionLauncher rememberLauncherForActivityResult ActivityResultContracts RequestPermission isGranted Boolean gt if isGranted onPermissionGranted else onPermissionDenied SideEffect requestLocationPermissionLauncher launch Manifest permission ACCESS FINE LOCATION Note Inititally I used the permissions library from accompanist It worked only if the permission is granted It did not work well when the permission denied and I want to request the permission again So I decided to use rememberLauncherForActivityResult instead Enable Location SettingWhen the location permission has already granted you want to make sure the location setting is turned on If it is off you want to request the user to turn it on Similar to request location permission above you use rememberLauncherForActivityResult to register enable location setting request callback val enableLocationSettingLauncher rememberLauncherForActivityResult contract ActivityResultContracts StartIntentSenderForResult activityResult gt if activityResult resultCode Activity RESULT OK onSuccess else onFailure To check whether the location setting is turned on you call SettingsClient checkLocationSettings API which returns the Task lt LocationSettingsResponse gt which allows you to set up the failure and success callbacks If the callback is failed it means the device location setting is off In that case you want to request user to enable it if it is resolvable exception is ResolvableApiException To do that you call ActivityResultLauncher launch API with the resolution PendingIntent that you get from the exception val locationRequest LocationRequest create apply priority Priority PRIORITY HIGH ACCURACY val locationRequestBuilder LocationSettingsRequest Builder addLocationRequest locationRequest val locationSettingsResponseTask LocationServices getSettingsClient context checkLocationSettings locationRequestBuilder build locationSettingsResponseTask addOnSuccessListener onSuccess locationSettingsResponseTask addOnFailureListener exception gt if exception is ResolvableApiException try val intentSenderRequest IntentSenderRequest Builder exception resolution build enableLocationSettingLauncher launch intentSenderRequest catch sendEx IntentSender SendIntentException sendEx printStackTrace else onFailure Refer to LocationSettingDialog in the source code Get the last known locationFinally you want to get the last known location which is also a current location if the device location setting is turned on First you set up the LocationCallback to receive the LocationResult which has the last known location information The callback is then removed to save power To request the location update you call FusedLocationProviderClient requestLocationUpdates API by passing in the LocationRequest LocationCallback and Looper SuppressLint MissingPermission fun requestLocationResultCallback fusedLocationProviderClient FusedLocationProviderClient locationResultCallback LocationResult gt Unit val locationCallback object LocationCallback override fun onLocationResult locationResult LocationResult super onLocationResult locationResult locationResultCallback locationResult fusedLocationProviderClient removeLocationUpdates this val locationRequest LocationRequest create apply interval fastestInterval priority Priority PRIORITY HIGH ACCURACY Looper myLooper let looper gt fusedLocationProviderClient requestLocationUpdates locationRequest locationCallback looper ConclusionThe app requests the location permission and request to enable location setting during start up It requests again when the user click in the GPS icon if requests haven t been granted It also moves the camera back to current position when the GPS icon is clicked For details and if you want to play around with the app refer to the following source code Source CodeGitHub Repository Demo SimpleGoogleMap See AlsoAndroid Development Tips and Tricks 2022-09-03 01:05:39
海外ニュース Japan Times latest articles LDP to delay report on lawmakers’ ties to Unification Church https://www.japantimes.co.jp/news/2022/09/03/national/politics-diplomacy/ldp-delay-unification-church-ties-report/ LDP to delay report on lawmakers ties to Unification ChurchAll LDP lawmakers excluding the leaders of both parliamentary chambers submitted their results by Friday s deadline and the results could come sometime next week 2022-09-03 10:10:47
ニュース BBC News - Home Bus fare cap: England charges to be held at £2 for three months https://www.bbc.co.uk/news/uk-england-62775639?at_medium=RSS&at_campaign=KARANGA announces 2022-09-03 01:49:47
ニュース BBC News - Home Cristina Fernández de Kirchner: Argentines rally after botched assassination attempt https://www.bbc.co.uk/news/world-latin-america-62775282?at_medium=RSS&at_campaign=KARANGA president 2022-09-03 01:30:23
ニュース BBC News - Home Why the folding phone revolution has a way to go https://www.bbc.co.uk/news/technology-62727710?at_medium=RSS&at_campaign=KARANGA editor 2022-09-03 01:03:11
ニュース BBC News - Home BBC exodus: What's behind the large number of presenters leaving? https://www.bbc.co.uk/news/entertainment-arts-62723769?at_medium=RSS&at_campaign=KARANGA talent 2022-09-03 01:25:08
ニュース BBC News - Home Cost of living: What do Covid, Ukraine and droughts have to do with my bills? https://www.bbc.co.uk/news/business-62752450?at_medium=RSS&at_campaign=KARANGA china 2022-09-03 01:06:55
ニュース BBC News - Home Charity uses online returns to help hard-up families https://www.bbc.co.uk/news/uk-62752864?at_medium=RSS&at_campaign=KARANGA online 2022-09-03 01:28:46
北海道 北海道新聞 【道スポ】コンサドーレ 劇的逆転勝利 6位・C大阪に2―1 貴重な勝ち点3で12位浮上 https://www.hokkaido-np.co.jp/article/725781/ 残留争い 2022-09-03 10:11:00
北海道 北海道新聞 1キロ1万3999円「ご祝儀相場」 札幌で秋サケ初競り https://www.hokkaido-np.co.jp/article/725780/ 競り 2022-09-03 10:03:17
ビジネス 東洋経済オンライン 気づけばよく見る「パンサー」再ブレイクの必然 超売れっ子の彼らにも多くの苦悩があった | テレビ | 東洋経済オンライン https://toyokeizai.net/articles/-/615361?utm_source=rss&utm_medium=http&utm_campaign=link_back 再ブレイク 2022-09-03 10:30:00

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)