Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Nova Api de Localização Android
Search
José Caique Oliveira
November 10, 2017
Programming
0
72
Nova Api de Localização Android
Slides usados no TDC Porto Alegre
José Caique Oliveira
November 10, 2017
Tweet
Share
More Decks by José Caique Oliveira
See All by José Caique Oliveira
Kotlin Flow
jcaiqueoliveira
0
110
Coroutines And Flow
jcaiqueoliveira
2
100
Testing your app
jcaiqueoliveira
0
260
Modularizando seu app
jcaiqueoliveira
0
68
Arquitetura para android
jcaiqueoliveira
6
320
Kotlin por onde começar?
jcaiqueoliveira
1
88
Introdução ao Android
jcaiqueoliveira
1
79
Arquitetura para projetos Android
jcaiqueoliveira
1
210
Kotlin 1.1
jcaiqueoliveira
0
120
Other Decks in Programming
See All in Programming
数十万行のプロジェクトを Scala 2から3に完全移行した
xuwei_k
0
1k
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
170
Запуск 1С:УХ в крупном энтерпрайзе: мечта и реальность ПМа
lamodatech
0
880
Monixと常駐プログラムの勘どころ / Scalaわいわい勉強会 #4
stoneream
0
330
テストコード書いてみませんか?
onopon
2
300
PHPで作るWebSocketサーバー ~リアクティブなアプリケーションを知るために~ / WebSocket Server in PHP - To know reactive applications
seike460
PRO
2
720
技術的負債と向き合うカイゼン活動を1年続けて分かった "持続可能" なプロダクト開発
yuichiro_serita
0
270
Fibonacci Function Gallery - Part 2
philipschwarz
PRO
0
210
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
1.3k
KubeCon + CloudNativeCon NA 2024 Overviewat Kubernetes Meetup Tokyo #68 / amsy810_k8sjp68
masayaaoyama
0
300
shadcn/uiを使ってReactでの開発を加速させよう!
lef237
0
240
「とりあえず動く」コードはよい、「読みやすい」コードはもっとよい / Code that 'just works' is good, but code that is 'readable' is even better.
mkmk884
6
1.3k
Featured
See All Featured
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
330
21k
The Cult of Friendly URLs
andyhume
78
6.1k
Docker and Python
trallard
43
3.2k
Visualization
eitanlees
146
15k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.4k
The Language of Interfaces
destraynor
155
24k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
29
950
Optimizing for Happiness
mojombo
376
70k
GraphQLとの向き合い方2022年版
quramy
44
13k
The World Runs on Bad Software
bkeepers
PRO
66
11k
Transcript
Nova API de localização para Android Diminuindo fricção
Caique Oliveira Graduado em Ciência da computação - UFS Android
developer - Stone Apresentação
Trabalhando com localização no Android
Implementar GooglePlayServicesClient - ConnectionCallbacks - OnConnectionFailedListener
ConnectionCallbacks override fun onConnected(p0: Bundle?){ } override fun onConnectionSuspended(p0: Int){
}
OnConnectionFailedListener override fun onConnectionFailed(p0: ConnectionResult) { }
Configurar GoogleApiClient fun initGoogleApiClient() { if (mGoogleApiClient != null) {
mGoogleApiClient = GoogleApiClient.Builder( this) .addConnectionCallbacks( this) .addOnConnectionFailedListener( this) .addApi(LocationServices. API) .build() } mGoogleApiClient?.connect() }
Conectar ao Play Services override fun onStart() { mGoogleApiClient?.connect() super.onStart()
}
Desconectar de acordo com o ciclo de vida override fun
onStop() { mGoogleApiClient?.disconnect() super.onStop() }
fun getLocation(): Location { return LocationServices.FusedLocationApi .getLastLocation(mGoogleApiClient) }
Meu Deus do Céu
Todo app é a mesma coisa
“É realmente necessário que eu mesmo controle o GoogleApiClient?”
“Eu realmente preciso controlar o ciclo de vida dele?”
Android Architecture Components
Android Architecture Components - Menor escrita de código - Framework
gerencia o ciclo de vida - Traz uma melhor experiência para o desenvolvedor
Reduzindo o atrito ao trabalhar com Location
implementation ‘com.google.android.gms:play-services-location:11.6.0’
LastLocation LocationServices.getFusedLocationProviderClient(this) .lastLocation.addOnSuccessListener({ location -> Log.e("location", location.toString()) })
implementa OnFailureListener override fun onFailure(p0: Exception) { val statusCode =
(p0 as ApiException).statusCode when (statusCode) { RESOLUTION_REQUIRED -> { //Fix in Settings." } SETTINGS_CHANGE_UNAVAILABLE -> { //Fix in Settings." } } }
LastLocation LocationServices.getFusedLocationProviderClient(this) .lastLocation.addOnSuccessListener({ location -> Log.v("location", location.toString()) }).addOnFailureListener(this)
Location Updates LocationServices.getFusedLocationProviderClient(this) .requestLocationUpdates( locationRequest = mLocationRequest, locationCallback = mLocationCallback,
looper = Looper.myLooper())
Location Updates - Callback val mLocationCallback = object : LocationCallback()
{ override fun onLocationResult(result: LocationResult?) { super.onLocationResult(result) Log.v("location",locationResult?.lastLocation?.toString()) } }
Location Updates - Request val mLocationRequest = LocationRequest() .setInterval(UPDATE_INTERVAL_IN_MILLISECONDS) .setFastestInterval(UPDATE_INTERVAL_IN_MILLISECONDS)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
Temos agora o foco para obter de forma simples uma
localização ou resolver um problema
Obrigado! twitter: @_josecaique email:
[email protected]
slack android dev br: caique
github: jcaiqueoliveira https://goo.gl/E1QsJg
Referências https://goo.gl/dLZ8X2 https://goo.gl/itG6pa
enter.stone.com.br